-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathml_model_telur.py
32 lines (24 loc) · 967 Bytes
/
ml_model_telur.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
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
# read dataset
df = pd.read_csv('dataset_telur.csv',
usecols=['pixel', 'volume', 'jarak'])
# delete outlier
# df.drop(1, inplace=True)
# -------------------------------- Modeling ML -----------------------------
#variabel x dan y.
x = df.drop(columns='volume')
y = df['volume']
#split data menjadi training and testing dengan porsi 80 : 20.
x_train, x_test, y_train, y_test = train_test_split(
x, y,
train_size=0.8, test_size=0.2,
random_state=4)
#object linear regresi.
lin_reg = LinearRegression()
#train the model menggunakan training data yang sudah displit.
lin_reg.fit(x_train.values, y_train.values)
def predict(jarak, pixel):
return lin_reg.predict([[pixel, jarak]])