-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtrain.py
More file actions
29 lines (19 loc) · 751 Bytes
/
train.py
File metadata and controls
29 lines (19 loc) · 751 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
import pandas as pd
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.tree import DecisionTreeRegressor
import pickle
#Read csv-file
data = pd.read_csv('data/auto-mpg.csv', sep=";")
#Shuffle data
data = data.sample(frac=1)
#'class'-column
y_variable = data['mpg']
#all columns that are not the 'class'-column -> all columns that contain the attributes
x_variables = data.loc[:, data.columns != 'mpg']
x_train, x_test, y_train, y_test = train_test_split(x_variables, y_variable, test_size=0.2)
regressor = DecisionTreeRegressor()
regressor = regressor.fit(x_train, y_train)
y_pred = regressor.predict(x_test)
file_to_write = open("models/baummethoden.pickle", "wb")
pickle.dump(regressor, file_to_write)