-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_models.py
66 lines (52 loc) · 1.58 KB
/
test_models.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
54
55
56
57
58
59
60
61
62
63
64
65
66
# test sdas file
# A greate place to test code
import pandas as pd
import plotly.express as px
from sklearn.linear_model import Lasso, LassoCV
from sklearn.model_selection import (
GridSearchCV,
cross_val_predict,
cross_val_score,
train_test_split,
)
from sklearn.svm import SVR
from analyzer import BaseAnalyzer
from gpxfun.analyzer_factory import AnalyzerFactory
from dash_app.app_data_functions import get_data_from_pickle_session
from utils.mylog import get_log
from gpxfun.prepare_data import get_prepared_data
log = get_log("gpxfun", 10)
# get data
d, _ = get_data_from_pickle_session("test")
def test_lasso(d):
# Test LASSO
dr = get_prepared_data(d, startendcluster=0)
a = AnalyzerFactory().get_analyzer("AnalyzeLasso")(dr)
a.analyze(alpha=0.1)
print(a.coeffs)
dr = get_prepared_data(d)
a = AnalyzerFactory().get_analyzer("AnalyzeSVR")(dr)
X = pd.get_dummies(dr[list(BaseAnalyzer.varformatdict.keys())])
dummycols = pd.Series(X.columns)
y = dr["speed"]
model = LassoCV(cv=10)
model.fit(X,y)
model.coef_
model = Lasso()
cross_val_predict(model,X,y)
scores=cross_val_score(model,X,y,cv=5)
print(scores)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
model=SVR()
model.fit(X_train,y_train)
yp=model.predict(X_test)
fig=px.scatter(x=y_test,y=yp)
fig.show()
parameters = {'kernel':('linear', 'rbf', 'poly'), 'degree':(2,3,4), 'C':[1, 10]}
clf=GridSearchCV(model,parameters)
clf.fit(X_train,y_train)
model=clf.best_estimator_
model.fit(X_train,y_train)
yp=model.predict(X_test)
fig=px.scatter(x=y_test,y=yp)
fig.show()