<jupyter_start><jupyter_text>dataset spliting<jupyter_code>X = df.drop(columns=["Price"])
y = df["Price"]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
X_train.shape, X_test.shape, y_train.shape, y_test.shape
df.head()<jupyter_output><empty_output><jupyter_text>Training<jupyter_code>from sklearn.model_selection import GridSearchCV
from jcopml.tuning import grid_search_params as gsp
from sklearn.svm import SVR
preprocessor = ColumnTransformer([
    ('numeric', num_pipe(), ["Year","Kilometers_Driven", "Mileage_kmpl", "Engine_CC", "Power_bhp", "Seats"]),
    ('categoric', cat_pipe(encoder='onehot'), ["Location", "Fuel_Type", "Transmission", "Owner_Type"]),
])


pipeline = Pipeline([
    ('prep', preprocessor),
    ('algo', SVR(max_iter=500))
])

model = GridSearchCV(pipeline, gsp.svm_params, cv=3, n_jobs=-1, verbose=1)
model.fit(X_train, y_train)

print(model.best_params_)
print(model.score(X_train, y_train), model.best_score_, model.score(X_test, y_test))<jupyter_output>Fitting 3 folds for each of 49 candidates, totalling 147 fits<jupyter_text>Scalling can help svm and knn<jupyter_code>preprocessor = ColumnTransformer([
    ('numeric', num_pipe(scaling="standard"), ["Year","Kilometers_Driven", "Mileage_kmpl", "Engine_CC", "Power_bhp", "Seats"]),
    ('categoric', cat_pipe(encoder='onehot'), ["Location", "Fuel_Type", "Transmission", "Owner_Type"]),
])


pipeline = Pipeline([
    ('prep', preprocessor),
    ('algo', SVR(max_iter=500))
])

model = GridSearchCV(pipeline, gsp.svm_params, cv=3, n_jobs=-1, verbose=1)
model.fit(X_train, y_train)

print(model.best_params_)
print(model.score(X_train, y_train), model.best_score_, model.score(X_test, y_test))
preprocessor = ColumnTransformer([
    ('numeric', num_pipe(scaling="robust"), ["Year","Kilometers_Driven", "Mileage_kmpl", "Engine_CC", "Power_bhp", "Seats"]),
    ('categoric', cat_pipe(encoder='onehot'), ["Location", "Fuel_Type", "Transmission", "Owner_Type"]),
])


pipeline = Pipeline([
    ('prep', preprocessor),
    ('algo', SVR(max_iter=500))
])

model = GridSearchCV(pipeline, gsp.svm_params, cv=3, n_jobs=-1, verbose=1)
model.fit(X_train, y_train)

print(model.best_params_)
print(model.score(X_train, y_train), model.best_score_, model.score(X_test, y_test))
preprocessor = ColumnTransformer([
    ('numeric', num_pipe(scaling="minmax"), ["Year","Kilometers_Driven", "Mileage_kmpl", "Engine_CC", "Power_bhp", "Seats"]),
    ('categoric', cat_pipe(encoder='onehot'), ["Location", "Fuel_Type", "Transmission", "Owner_Type"]),
])


pipeline = Pipeline([
    ('prep', preprocessor),
    ('algo', SVR(max_iter=500))
])

model = GridSearchCV(pipeline, gsp.svm_params, cv=3, n_jobs=-1, verbose=1)
model.fit(X_train, y_train)

print(model.best_params_)
print(model.score(X_train, y_train), model.best_score_, model.score(X_test, y_test))
from luwiji.svm import demo

demo.poly_features()<jupyter_output><empty_output><jupyter_text>polinomial<jupyter_code>gsp.svm_poly_params
preprocessor = ColumnTransformer([
    ('numeric', num_pipe(poly=2 ,scaling="robust"), ["Year","Kilometers_Driven", "Mileage_kmpl", "Engine_CC", "Power_bhp", "Seats"]),
    ('categoric', cat_pipe(encoder='onehot'), ["Location", "Fuel_Type", "Transmission", "Owner_Type"]),
])


pipeline = Pipeline([
    ('prep', preprocessor),
    ('algo', SVR(max_iter=500))
])

model = GridSearchCV(pipeline, gsp.svm_poly_params, cv=3, n_jobs=-1, verbose=1)
model.fit(X_train, y_train)

print(model.best_params_)
print(model.score(X_train, y_train), model.best_score_, model.score(X_test, y_test))<jupyter_output>Fitting 3 folds for each of 294 candidates, totalling 882 fits<jupyter_text>save model<jupyter_code>save_model(model.best_estimator_, "carPrice.pkl")<jupyter_output>Model is pickled as model/carPrice.pkl
{'fraction_non_alphanumeric': 0.17105263157894737, 'fraction_numerical': 0.01263157894736842, 'mean_word_length': 7.964622641509434, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '620480', 'license': 'MIT', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1445, 'n_words': 242, 'path': '05 - SVM/part2-supportVectorRegression.ipynb', 'repo_name': 'FransiscoReadyPermana/supervised_learning', 'size': '3800'}