- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp12reg.py
More file actions
Latest commit
31 lines (22 loc) · 996 Bytes
/
Copy pathp12reg.py
File metadata and controls
31 lines (22 loc) · 996 Bytes
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
fromscipyimportstats
importnumpyasnp
importpandasaspd
importmatplotlib.pyplotasplt
importsklearn
x=np.array([5, 4, 6, 5, 5, 5, 6, 6, 2, 7, 7]) # Convert to NumPy array
y=np.array([85, 103, 70, 82, 89, 98, 66, 95, 169, 70, 48]) # Convert to NumPy array
dataku=pd.DataFrame({'x': x, 'y': y})
fromsklearn.model_selectionimporttrain_test_split
x_train, x_test, y_train, y_test=train_test_split(x.reshape(-1, 1), y, test_size=0.2, random_state=0)
fromsklearn.linear_modelimportLinearRegression
regressor=LinearRegression()
regressor.fit(x_train, y_train)
y_pred=regressor.predict(x_test)
x_line=np.linspace(np.min(x), np.max(x), num=100).reshape(-1, 1)
y_line=regressor.predict(x_line) # Predict y-axis values for the x-axis sequence
plt.scatter(dataku.x, dataku.y)
plt.plot(x_line, y_line, color='red') # Plot the predicted values
plt.xlabel("Usia Mobil(tahun)")
plt.ylabel("Harga Mobil($100)")
plt.title("Grafik Usia Mobil vs Harga Mobil")
plt.show()