{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"\nimport numpy as np\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import r2_score\ndata = {\n    'Hours_Studied': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n    'Marks_Scored': [22, 45, 50, 55, 63, 70, 74, 80, 88, 95]\n}\n\ndf = pd.DataFrame(data)\n\n\nprint(\"📊 Student Data:\")\nprint(df)\n\n\nX = df[['Hours_Studied']]  # Input (Independent variable)\ny = df['Marks_Scored']     # Output (Dependent variable)\n\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\nmodel = LinearRegression()\nmodel.fit(X_train, y_train)\n\ny_pred = model.predict(X_test)\n\n\nscore = r2_score(y_test, y_pred)\nprint(\"\\n✅ Model Accuracy (R² Score):\", round(score * 100, 2), \"%\")\n\nhours = pd.DataFrame({'Hours_Studied': [7]})\npredicted_marks = model.predict(hours)\nprint(f\"\\n📈 Agar koi student 7 ghante padhta hai to expected marks hain: {predicted_marks[0]:.2f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-29T17:16:10.007531Z","iopub.execute_input":"2025-10-29T17:16:10.007849Z","iopub.status.idle":"2025-10-29T17:16:10.028302Z","shell.execute_reply.started":"2025-10-29T17:16:10.007811Z","shell.execute_reply":"2025-10-29T17:16:10.027301Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# My First Machine Learning Project 🎯\n\nIs project me maine ek simple Linear Regression model banaya hai  \njo students ke *Hours Studied* ke basis par *Marks Scored* predict karta hai.  \n\nModel ne data ko training aur testing parts me divide karke accuracy check ki hai.  \nR² Score batata hai ki model kitna accurate hai.  \n\nExample:  \nAgar koi student 7 ghante padhta hai, to model uske expected marks predict karta hai.  \n\nYe mera pehla Kaggle Machine Learning project hai 🙌","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.linear_model import LinearRegression\n\ndata = {\n    'Hours_Studied': [1,2,3,4,5,6,7,8,9,10],\n    'Marks_Scored': [22,45,50,55,63,70,74,80,88,95]\n}\ndf = pd.DataFrame(data)\n\nprint(df)\n\n\nplt.scatter(df['Hours_Studied'], df['Marks_Scored'])\nplt.xlabel('Hours Studied')\nplt.ylabel('Marks Scored')\nplt.title('Linear Relationship between Study Hours and Marks')\nplt.show()\n\n\nX = df[['Hours_Studied']]\ny = df['Marks_Scored']\nmodel = LinearRegression()\nmodel.fit(X, y)\n\nhours = 7\npredicted_marks = model.predict(pd.DataFrame([[hours]], columns=['Hours_Studied']))\nprint(f\"अगर कोई {hours} घंटे पढ़े, तो अनुमानित अंक होंगे: {predicted_marks[0]:.2f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-30T10:24:09.065958Z","iopub.execute_input":"2025-10-30T10:24:09.066319Z","iopub.status.idle":"2025-10-30T10:24:09.221475Z","shell.execute_reply.started":"2025-10-30T10:24:09.066297Z","shell.execute_reply":"2025-10-30T10:24:09.219706Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### 📊 Result Explanation\n\nThe above graph clearly shows that the more hours a student studies,  \nthe higher their marks will be.  \n\nThis is a **Linear Regression Model** that shows the relationship between  \nhours studied and marks scored.  \n\n✅ If a student studies for 7 hours, the predicted score is **74.85**.\n\n---\n\n👉 This is a basic Machine Learning project.  \nNext, we’ll move to a more advanced one — **House Price Prediction using Multiple Linear Regression.**","metadata":{}},{"cell_type":"code","source":"\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_squared_error, r2_score\n\nurl = \"https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv\"\ndf = pd.read_csv(url)\ndf.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-30T10:30:38.456322Z","iopub.execute_input":"2025-10-30T10:30:38.456863Z","iopub.status.idle":"2025-10-30T10:30:39.099039Z","shell.execute_reply.started":"2025-10-30T10:30:38.456840Z","shell.execute_reply":"2025-10-30T10:30:39.098053Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nX = df.drop('medv', axis=1)   # 'medv' = Median value of house (target)\ny = df['medv']\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n\nmodel = LinearRegression()\nmodel.fit(X_train, y_train)\n\n\ny_pred = model.predict(X_test)\n\n\nmse = mean_squared_error(y_test, y_pred)\nr2 = r2_score(y_test, y_pred)\n\nprint(f\"Mean Squared Error: {mse:.2f}\")\nprint(f\"R² Score: {r2:.2f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-30T10:32:39.192172Z","iopub.execute_input":"2025-10-30T10:32:39.192468Z","iopub.status.idle":"2025-10-30T10:32:39.231073Z","shell.execute_reply.started":"2025-10-30T10:32:39.192449Z","shell.execute_reply":"2025-10-30T10:32:39.230105Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(8,5))\nplt.scatter(y_test, y_pred, color='blue')\nplt.xlabel(\"Actual Prices\")\nplt.ylabel(\"Predicted Prices\")\nplt.title(\"Actual vs Predicted House Prices\")\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-30T10:33:53.451950Z","iopub.execute_input":"2025-10-30T10:33:53.452278Z","iopub.status.idle":"2025-10-30T10:33:53.594874Z","shell.execute_reply.started":"2025-10-30T10:33:53.452260Z","shell.execute_reply":"2025-10-30T10:33:53.593893Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n\nnew_data = pd.DataFrame({\n    'crim': [0.1],\n    'zn': [25.0],\n    'indus': [5.0],\n    'chas': [0],\n    'nox': [0.4],\n    'rm': [6.0],\n    'age': [40.0],\n    'dis': [5.0],\n    'rad': [4.0],\n    'tax': [300.0],\n    'ptratio': [15.0],\n    'b': [380.0],\n    'lstat': [5.0]\n})\n\npredicted_price = model.predict(new_data)\nprint(f\"🏠 Estimated House Price: ${predicted_price[0]*1000:.2f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-30T10:34:37.606916Z","iopub.execute_input":"2025-10-30T10:34:37.607184Z","iopub.status.idle":"2025-10-30T10:34:37.616245Z","shell.execute_reply.started":"2025-10-30T10:34:37.607168Z","shell.execute_reply":"2025-10-30T10:34:37.615203Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":" 🏠 House Price Prediction using Linear Regression\n\n\nThis project predicts house prices using the **Boston Housing Dataset**.  \nBy applying a **Linear Regression** model, it estimates the median value of homes based on various factors like crime rate, number of rooms, tax rate, and more.\n\n\n1. Importing and exploring the dataset 📊  \n2. Splitting data into training & testing sets  \n3. Training a Linear Regression model  \n4. Evaluating model accuracy (R² = 0.67)  \n5. Visualizing actual vs predicted prices  \n6. Predicting the price of a new house 🏠  \n\n---\n\n## 📈 Model Performance\n- **Mean Squared Error:** 24.29  \n- **R² Score:** 0.67  \n\n---\n\n## 💡 Conclusion\nThe Linear Regression model provides a decent accuracy in predicting house prices.  \nWith more data cleaning and feature engineering, the accuracy can be improved further.\n\n\n`#MachineLearning` `#LinearRegression` `#Kaggle` `#DataScience` `#Python`","metadata":{}}]}