Tags » Python

Linear Regression Basics


Linear Regression is a simple, yet powerful method for understanding linear relationships between variables in a collection of observations.  For a given ith observation there is a set of n independent variables {x1, x2, x3, …, xn}i and one dependent variable yi, and the assumption is that yi is linear function of the independent variables. 948 more words

Linear Regression

Custom FileField Bawaan Django untuk Membatasi Jenis File Image dan Sizenya

Saya kepingin image yang saya upload hanya berjenis jpg dan gif saja saja dengan batasan sizenya hanya kurang atau sama dengan 2 mb ? Bisakah ? 278 more words


Python OOP #2 - Sınıf Değişkenleri

apply_raise() adında yeni bir fonksiyon tanımlayalım. Bu fonksiyon işçilerin maaşlarını artıracak. Artırma miktarını raise_amount değişkeninde saklayacağım.

class Employee():

    number_of_emps = 0
    raise_amount = 1.04

    def __init__(self, fname, lname, pay):
        self.fname = fname
        self.lname = lname
        self.pay = pay
        self.mail = fname + "." + lname + "@company.com"

        Employee.number_of_emps += 1

    def fullname(self):
        return self.fname + " " + self.lname

    def apply_raise(self):
        self.pay = int(self.pay * self.raise_amount)

emp1 = Employee("Bob", "Hawkes", 5000)
emp2 = Employee("Alice", "Banas", 3500) 249 more words

REDIS: Iterating through database with SCAN

It has recently come to my attention that iterating though stuff is quite important. Be it a lists, sets or hashes. This can generally be accomplished using the general… 812 more words

Linear regression example

Final code:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('Droid control - wind speed.csv')
print df.head()
print df.describe()
print df.info()

plt.scatter(df['Wind speed'], df['Control metrics'], color = 'red')
plt.title('Control action / wind speed')
plt.xlabel('Wind speed (km/h)')
plt.ylabel('Control metrics')

X = df.iloc[:, :-1].values
y = df.iloc[:, 1].values

X_squares = X[:,0] ** 2
X_times_Y = X[:,0] * y
N = len(X)

# b = ((∑X^2)(∑Y) – (∑X)(∑XY)) / (N(∑X^2) – (∑X)^2)

b1 = X_squares.sum() * y.sum() # (∑X^2)(∑Y)
b2 = X.sum() * X_times_Y.sum() # (∑X)(∑XY)
b3 = N * X_squares.sum() # N(∑X^2)
b4 = X.sum() ** 2 # (∑X)^2

b = (b1 - b2) / (b3 - b4)

# m = (N(∑XY) – (∑X)(∑Y)) / (N(∑X^2) – (∑X)^2)

m1 = N * X_times_Y.sum() # (∑X^2)(∑Y)
m2 = X.sum() * y.sum() # (∑X)(∑XY)
m3 = N * X_squares.sum() # N(∑X^2)
m4 = X.sum() ** 2 # (∑X)^2

m = (m1 - m2) / (m3 - m4)

manual_linear_regression = []
for el in X:
    f_of_X = b + m * el
    manual_linear_regression = np.append(manual_linear_regression, f_of_X)

lin_equation = 'Y = {} + {}X'.format(b, m)

plt.scatter(df['Wind speed'], df['Control metrics'], color = 'red', label = 'Original data')
plt.scatter(df['Wind speed'], manual_linear_regression, color = 'blue', label = lin_equation)
plt.title('Control action / wind speed')
plt.xlabel('Wind speed (km/h)')
plt.ylabel('Control metrics')
plt.legend(loc = 'upper left')
… 1,379 more words

Why we should learn Python?

Python is a general-purpose language, which means it can be used to build just about anything, which will be made easy with the right tools/libraries. 483 more words


OOP vs Functional: No contest!

Moving to kotlin, the question can arise: “should I program in OOP (Object Oriented Programming) style, or move to Functional programming?”.  This page examines reviews what Object Oriented programming really means, what functional programing is, and outlines how there is no incompatibility if the correct approach to OOP is in place, and the two paradigms are best when combined. 1,325 more words