text_plain_output_1.png image_output_1.png
from sklearn import linear_model

import matplotlib.pyplot as plt

import numpy as np

import pandas

import seaborn as sns

df = pandas.read_csv('../input/mobile-price-classification/train.csv')

corr = df.corr()

x = df[['clock_speed', 'fc', 'px_height', 'px_width', 'three_g', 'four_g', 'ram']]
y = df['price_range']
regr = linear_model.LinearRegression()
regr.fit(x.values, y)

predicted = regr.predict([[2.0, 10, 1500, 1200, 1, 1, 2000]])
predicted = regr.predict([[2.0, 10, 1500, 1200, 1, 1, 4080]])

df.isnull().sum()

df.notnull().sum()

def function(x, a):
    f = a[2] * x * x + a[1] * x + a[0]
    return f
def grad(x, a):
    g = 2 * a[2] * x + a[1]
    return g
x = df[['clock_speed', 'fc', 'px_height', 'px_width', 'three_g', 'four_g', 'ram']]
y = df['price_range']
f = function(x, y)

x = df[['ram']]
y = df['price_range']

import numpy as np

def find_theta(X, y):
    m = X.shape[0]
    X = np.append(X, np.ones((m,1)), axis=1)    
    theta = np.dot(np.linalg.inv(np.dot(X.T, X)), np.dot(X.T, y))
    return theta

def predict(X):
    X = np.append(X, np.ones((X.shape[0],1)), axis=1)
    preds = np.dot(X, theta)
    return preds

theta = find_theta(x, y)
print(theta)

preds = predict(x)
fig = plt.figure(figsize=(8,6))
plt.plot(x, y, 'b.')
plt.plot(x, preds, 'c-')
plt.xlabel('Input')
plt.ylabel('target')

x = df[['ram']]
y = df['price_range']
regr2 = linear_model.LinearRegression()
regr2.fit(x.values, y)
arr = []
index = []
for i in range(0, 4000, 1):
    predicted = regr2.predict([[i]])
    arr.append(predicted[0])
    index.append(i)
fig = plt.figure(figsize=(8, 6))
plt.plot(x, y, 'b.')
plt.plot(index, arr, 'c-')