diff --git a/House_Price_Prediction/California.ipynb b/House_Price_Prediction/California.ipynb new file mode 100644 index 0000000..a648a25 --- /dev/null +++ b/House_Price_Prediction/California.ipynb @@ -0,0 +1,414 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "594c4a2d", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "from sklearn import linear_model\n", + "from sklearn.model_selection import train_test_split" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "fca5993b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'data': array([[ 8.3252 , 41. , 6.98412698, ..., 2.55555556,\n", + " 37.88 , -122.23 ],\n", + " [ 8.3014 , 21. , 6.23813708, ..., 2.10984183,\n", + " 37.86 , -122.22 ],\n", + " [ 7.2574 , 52. , 8.28813559, ..., 2.80225989,\n", + " 37.85 , -122.24 ],\n", + " ...,\n", + " [ 1.7 , 17. , 5.20554273, ..., 2.3256351 ,\n", + " 39.43 , -121.22 ],\n", + " [ 1.8672 , 18. , 5.32951289, ..., 2.12320917,\n", + " 39.43 , -121.32 ],\n", + " [ 2.3886 , 16. , 5.25471698, ..., 2.61698113,\n", + " 39.37 , -121.24 ]]), 'target': array([4.526, 3.585, 3.521, ..., 0.923, 0.847, 0.894]), 'frame': None, 'target_names': ['MedHouseVal'], 'feature_names': ['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude'], 'DESCR': '.. _california_housing_dataset:\\n\\nCalifornia Housing dataset\\n--------------------------\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 20640\\n\\n :Number of Attributes: 8 numeric, predictive attributes and the target\\n\\n :Attribute Information:\\n - MedInc median income in block group\\n - HouseAge median house age in block group\\n - AveRooms average number of rooms per household\\n - AveBedrms average number of bedrooms per household\\n - Population block group population\\n - AveOccup average number of household members\\n - Latitude block group latitude\\n - Longitude block group longitude\\n\\n :Missing Attribute Values: None\\n\\nThis dataset was obtained from the StatLib repository.\\nhttps://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html\\n\\nThe target variable is the median house value for California districts,\\nexpressed in hundreds of thousands of dollars ($100,000).\\n\\nThis dataset was derived from the 1990 U.S. census, using one row per census\\nblock group. A block group is the smallest geographical unit for which the U.S.\\nCensus Bureau publishes sample data (a block group typically has a population\\nof 600 to 3,000 people).\\n\\nA household is a group of people residing within a home. Since the average\\nnumber of rooms and bedrooms in this dataset are provided per household, these\\ncolumns may take surprisingly large values for block groups with few households\\nand many empty houses, such as vacation resorts.\\n\\nIt can be downloaded/loaded using the\\n:func:`sklearn.datasets.fetch_california_housing` function.\\n\\n.. topic:: References\\n\\n - Pace, R. Kelley and Ronald Barry, Sparse Spatial Autoregressions,\\n Statistics and Probability Letters, 33 (1997) 291-297\\n'}\n" + ] + } + ], + "source": [ + "from sklearn.datasets import fetch_california_housing\n", + "housing = fetch_california_housing()\n", + "print(housing)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "7b4a4ea3", + "metadata": {}, + "outputs": [], + "source": [ + "#transforming dataset to data frame\n", + "#feature_names --> column names\n", + "#data --> required data or independent variable x\n", + "#target --> price of house or dependent variable y\n", + "\n", + "df_x = pd.DataFrame(housing.data, columns = housing.feature_names)\n", + "df_y = pd.DataFrame(housing.target)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "406c5014", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + " | MedInc | \n", + "HouseAge | \n", + "AveRooms | \n", + "AveBedrms | \n", + "Population | \n", + "AveOccup | \n", + "Latitude | \n", + "Longitude | \n", + "
---|---|---|---|---|---|---|---|---|
count | \n", + "20640.000000 | \n", + "20640.000000 | \n", + "20640.000000 | \n", + "20640.000000 | \n", + "20640.000000 | \n", + "20640.000000 | \n", + "20640.000000 | \n", + "20640.000000 | \n", + "
mean | \n", + "3.870671 | \n", + "28.639486 | \n", + "5.429000 | \n", + "1.096675 | \n", + "1425.476744 | \n", + "3.070655 | \n", + "35.631861 | \n", + "-119.569704 | \n", + "
std | \n", + "1.899822 | \n", + "12.585558 | \n", + "2.474173 | \n", + "0.473911 | \n", + "1132.462122 | \n", + "10.386050 | \n", + "2.135952 | \n", + "2.003532 | \n", + "
min | \n", + "0.499900 | \n", + "1.000000 | \n", + "0.846154 | \n", + "0.333333 | \n", + "3.000000 | \n", + "0.692308 | \n", + "32.540000 | \n", + "-124.350000 | \n", + "
25% | \n", + "2.563400 | \n", + "18.000000 | \n", + "4.440716 | \n", + "1.006079 | \n", + "787.000000 | \n", + "2.429741 | \n", + "33.930000 | \n", + "-121.800000 | \n", + "
50% | \n", + "3.534800 | \n", + "29.000000 | \n", + "5.229129 | \n", + "1.048780 | \n", + "1166.000000 | \n", + "2.818116 | \n", + "34.260000 | \n", + "-118.490000 | \n", + "
75% | \n", + "4.743250 | \n", + "37.000000 | \n", + "6.052381 | \n", + "1.099526 | \n", + "1725.000000 | \n", + "3.282261 | \n", + "37.710000 | \n", + "-118.010000 | \n", + "
max | \n", + "15.000100 | \n", + "52.000000 | \n", + "141.909091 | \n", + "34.066667 | \n", + "35682.000000 | \n", + "1243.333333 | \n", + "41.950000 | \n", + "-114.310000 | \n", + "
LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
LinearRegression()