-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMl_lab4.py
53 lines (43 loc) · 1.38 KB
/
Ml_lab4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'''import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt # Plotting and Visualizing data
import os
import statsmodels.api as sm
data = pd.read_csv('/Users/subhangisati/Downloads/Iris.csv')
x=data["Species"]
y=data.drop(["Species"],axis=1)
x=sm.add_constant(x)
model=sm.OLS(y,x).fit()
summary = model.summary()
print(summary)
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.33)
print(x[:10])
print('\n')
print(y[:10])
from sklearn.linear_model import LinearRegression
# create an empty linear regression model like below and give it a good variable name
radio_model = LinearRegression()
# to create the model, we use fit(x,y)
radio_model.fit(x,y)
y_pred = radio_model.predict(x)
plt.scatter(x,y,color = 'b')
plt.plot(x,radio_model.predict(x),color = 'r')
plt.title('Sales v/s Radio Budget')
plt.xlabel('Sales')
plt.ylabel('Radio Budget')
plt.show()
plt.scatter(x, y)'''
import pandas
import statsmodels.api as sm
df = pandas.read_csv("/Users/subhangisati/Downloads/restaurants.csv")
X = df['Food_Quality']
Y = df['Price']
X = sm.add_constant(X)
model = sm.OLS(Y, X).fit()
summary = model.summary()
print(summary)
'''import matplotlib.pyplot as plt
import seaborn as sns
sns.scatterplot(x='Food_Quality',y='Price',hue='Food_Quality')
plt.show()'''