text_plain_output_1.png
from sklearn.linear_model import LinearRegression

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

data = pd.read_csv('../input/mobile-phone-rating/mobile phone rating by dxo.csv', parse_dates=True)

data.shape

data.dtypes

data['price'] = data['price'].apply(lambda x: str(x).replace('$', '') if '$' in str(x) else str(x))
data['price'] = data['price'].apply(lambda x: float(x))

data.isnull().sum()

data['camera'].fillna(data['camera'].mean(), inplace=True)
data['selfie'].fillna(data['selfie'].median(), inplace=True)
data['audio'].fillna(data['audio'].mean(), inplace=True)
data['battery'].fillna(data['battery'].mean(), inplace=True)
data['display'].fillna(data['display'].median(), inplace=True)

data.isnull().sum()

data2 = data[['price', 'camera', 'battery']]

X = data2.drop(columns=['price'])
y = data2['price']

model = LinearRegression()
model.fit(X.values, y)

model.score(X.values, y)

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 = data2.drop(columns=['price'])
y = data2['price']
f = function(X, y)

x = data[['battery']]
y = data['price']
plt.plot(x, y, 'r.')