decisionscience/trial1
0
1{2 "cells": [3 {4 "cell_type": "code",5 "execution_count": 1,6 "id": "e2d9e6fa",7 "metadata": {},8 "outputs": [],9 "source": [10 "import seaborn as sns\n",11 "import pandas as pd\n",12 "from sklearn.model_selection import train_test_split\n",13 "from sklearn.linear_model import LinearRegression\n",14 "from sklearn.metrics import mean_squared_error, r2_score\n",15 "\n",16 "# Load dataset\n",17 "df = sns.load_dataset('mpg')\n",18 "df.dropna(inplace=True) # Dropping missing values"19 ]20 },21 {22 "cell_type": "code",23 "execution_count": 2,24 "id": "6eb9757f",25 "metadata": {},26 "outputs": [],27 "source": [28 "# Selecting relevant features for simplicity\n",29 "features = df[['cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'model_year']]\n",30 "target = df['mpg']\n",31 "\n",32 "# Splitting the dataset into training and testing sets\n",33 "X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2, random_state=42)"34 ]35 },36 {37 "cell_type": "code",38 "execution_count": 4,39 "id": "72821417",40 "metadata": {},41 "outputs": [],42 "source": [43 "# Create and train the model\n",44 "model = LinearRegression()\n",45 "model.fit(X_train, y_train)\n",46 "\n",47 "# Predictions and Evaluation\n",48 "y_pred = model.predict(X_test)"49 ]50 },51 {52 "cell_type": "code",53 "execution_count": 6,54 "id": "5dc111db",55 "metadata": {},56 "outputs": [57 {58 "name": "stdout",59 "output_type": "stream",60 "text": [61 "Requirement already satisfied: joblib in c:\\users\\user\\anaconda3\\lib\\site-packages (1.2.0)\n"62 ]63 }64 ],65 "source": [66 "#!pip install joblib"67 ]68 },69 {70 "cell_type": "code",71 "execution_count": 7,72 "id": "c41776ae",73 "metadata": {},74 "outputs": [],75 "source": [76 "import joblib"77 ]78 },79 {80 "cell_type": "code",81 "execution_count": 8,82 "id": "318d866d",83 "metadata": {},84 "outputs": [85 {86 "data": {87 "text/plain": [88 "['mpg_model.pkl']"89 ]90 },91 "execution_count": 8,92 "metadata": {},93 "output_type": "execute_result"94 }95 ],96 "source": [97 "# Save the model\n",98 "joblib.dump(model, 'mpg_model.pkl')"99 ]100 },101 {102 "cell_type": "code",103 "execution_count": null,104 "id": "7636f0d3",105 "metadata": {},106 "outputs": [],107 "source": []108 }109 ],110 "metadata": {111 "kernelspec": {112 "display_name": "Python 3 (ipykernel)",113 "language": "python",114 "name": "python3"115 },116 "language_info": {117 "codemirror_mode": {118 "name": "ipython",119 "version": 3120 },121 "file_extension": ".py",122 "mimetype": "text/x-python",123 "name": "python",124 "nbconvert_exporter": "python",125 "pygments_lexer": "ipython3",126 "version": "3.11.5"127 }128 },129 "nbformat": 4,130 "nbformat_minor": 5131}132 