Delete Untitled-1.ipynb
Browse files- Untitled-1.ipynb +0 -113
Untitled-1.ipynb
DELETED
|
@@ -1,113 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": 1,
|
| 6 |
-
"metadata": {},
|
| 7 |
-
"outputs": [
|
| 8 |
-
{
|
| 9 |
-
"name": "stdout",
|
| 10 |
-
"output_type": "stream",
|
| 11 |
-
"text": [
|
| 12 |
-
"Test MSE: 1.1890003835138339\n",
|
| 13 |
-
"0.9544317686906099\n"
|
| 14 |
-
]
|
| 15 |
-
}
|
| 16 |
-
],
|
| 17 |
-
"source": [
|
| 18 |
-
"import pandas as pd\n",
|
| 19 |
-
"from sklearn.model_selection import train_test_split\n",
|
| 20 |
-
"from sklearn.ensemble import HistGradientBoostingRegressor\n",
|
| 21 |
-
"from sklearn.metrics import mean_squared_error,r2_score\n",
|
| 22 |
-
"import pickle\n",
|
| 23 |
-
"\n",
|
| 24 |
-
"# Load the dataset from CSV\n",
|
| 25 |
-
"selected_columns = ['Process type', 'Part Od', 'Part ID', 'Part Width', 'Finish Wt', 'Input Weight']\n",
|
| 26 |
-
"data = pd.read_csv('C:/Users/Samridh Joshi/Downloads/Data_4.csv', usecols=selected_columns)\n",
|
| 27 |
-
"\n",
|
| 28 |
-
"# Assuming 'Input Weight' is the target variable, and other columns are features\n",
|
| 29 |
-
"X = data.drop(columns=['Input Weight'])\n",
|
| 30 |
-
"y = data['Input Weight']\n",
|
| 31 |
-
"\n",
|
| 32 |
-
"# Split the data into training and testing sets (80% train, 20% test)\n",
|
| 33 |
-
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
|
| 34 |
-
"\n",
|
| 35 |
-
"from sklearn.model_selection import RandomizedSearchCV\n",
|
| 36 |
-
"from scipy.stats import uniform, randint\n",
|
| 37 |
-
"\n",
|
| 38 |
-
"# Define the parameter grid\n",
|
| 39 |
-
"param_dist = {\n",
|
| 40 |
-
" 'learning_rate': uniform(0.01, 0.2),\n",
|
| 41 |
-
" 'max_iter': randint(100, 1000),\n",
|
| 42 |
-
" 'max_leaf_nodes': randint(10, 50),\n",
|
| 43 |
-
" 'max_depth': randint(3, 10),\n",
|
| 44 |
-
" 'min_samples_leaf': randint(1, 20),\n",
|
| 45 |
-
" 'max_bins': randint(50, 256),\n",
|
| 46 |
-
" 'l2_regularization': uniform(0, 1),\n",
|
| 47 |
-
" 'early_stopping': [True, False]\n",
|
| 48 |
-
"}\n",
|
| 49 |
-
"\n",
|
| 50 |
-
"# Instantiate the model\n",
|
| 51 |
-
"model = HistGradientBoostingRegressor()\n",
|
| 52 |
-
"\n",
|
| 53 |
-
"# Instantiate the RandomizedSearchCV object\n",
|
| 54 |
-
"random_search = RandomizedSearchCV(model, param_distributions=param_dist, n_iter=100, cv=5, random_state=42, n_jobs=-1)\n",
|
| 55 |
-
"\n",
|
| 56 |
-
"# Fit the random search model\n",
|
| 57 |
-
"random_search.fit(X_train, y_train)\n",
|
| 58 |
-
"\n",
|
| 59 |
-
"# Get the best estimator\n",
|
| 60 |
-
"best_model = random_search.best_estimator_\n",
|
| 61 |
-
"\n",
|
| 62 |
-
"# Use the best model to predict on the test set\n",
|
| 63 |
-
"y_pred = best_model.predict(X_test)\n",
|
| 64 |
-
"\n",
|
| 65 |
-
"\n",
|
| 66 |
-
"\n",
|
| 67 |
-
"# If you want to evaluate the performance, you can compute the MSE on the test set\n",
|
| 68 |
-
"from sklearn.metrics import mean_squared_error\n",
|
| 69 |
-
"mse_test = mean_squared_error(y_test, y_pred)\n",
|
| 70 |
-
"r_square=r2_score(y_test, y_pred)\n",
|
| 71 |
-
"print(\"Test MSE: \", mse_test)\n",
|
| 72 |
-
"print(r_square)\n",
|
| 73 |
-
"\n",
|
| 74 |
-
"\n",
|
| 75 |
-
"# # Train the model\n",
|
| 76 |
-
"# model = HistGradientBoostingRegressor()\n",
|
| 77 |
-
"# model.fit(X_train, y_train)\n",
|
| 78 |
-
"\n",
|
| 79 |
-
"\n",
|
| 80 |
-
"# test_predictions = model.predict(X_test)\n",
|
| 81 |
-
"\n",
|
| 82 |
-
"# test_mse = mean_squared_error(y_test, test_predictions)\n",
|
| 83 |
-
"\n",
|
| 84 |
-
"# print(\"Test MSE:\", test_mse)\n",
|
| 85 |
-
"\n",
|
| 86 |
-
"# Save the model to disk\n",
|
| 87 |
-
"with open('best_model.pkl', 'wb') as model_file:\n",
|
| 88 |
-
" pickle.dump(best_model, model_file)\n"
|
| 89 |
-
]
|
| 90 |
-
}
|
| 91 |
-
],
|
| 92 |
-
"metadata": {
|
| 93 |
-
"kernelspec": {
|
| 94 |
-
"display_name": "base",
|
| 95 |
-
"language": "python",
|
| 96 |
-
"name": "python3"
|
| 97 |
-
},
|
| 98 |
-
"language_info": {
|
| 99 |
-
"codemirror_mode": {
|
| 100 |
-
"name": "ipython",
|
| 101 |
-
"version": 3
|
| 102 |
-
},
|
| 103 |
-
"file_extension": ".py",
|
| 104 |
-
"mimetype": "text/x-python",
|
| 105 |
-
"name": "python",
|
| 106 |
-
"nbconvert_exporter": "python",
|
| 107 |
-
"pygments_lexer": "ipython3",
|
| 108 |
-
"version": "3.11.4"
|
| 109 |
-
}
|
| 110 |
-
},
|
| 111 |
-
"nbformat": 4,
|
| 112 |
-
"nbformat_minor": 2
|
| 113 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|