Files
fenago f3b24b4b7f added
2021-02-07 15:16:01 +05:00

176 lines
3.8 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "tK6L5s-hoLI7"
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import statsmodels.formula.api as smf\n",
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "Q2pZADxloUbD"
},
"outputs": [],
"source": [
"rawBostonData = pd.read_csv('../Dataset/Boston.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "Hylk6zVIoVyu"
},
"outputs": [],
"source": [
"rawBostonData = rawBostonData.dropna()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "RmcO-usHoW3d"
},
"outputs": [],
"source": [
"rawBostonData = rawBostonData.drop_duplicates()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "8v1TTJ8XoarG"
},
"outputs": [],
"source": [
"renamedBostonData = rawBostonData.rename(columns = {'CRIM':'crimeRatePerCapita',\n",
" ' ZN ':'landOver25K_sqft',\n",
" 'INDUS ':'non-retailLandProptn',\n",
" 'CHAS':'riverDummy',\n",
" 'NOX':'nitrixOxide_pp10m',\n",
" 'RM':'AvgNo.RoomsPerDwelling',\n",
" 'AGE':'ProptnOwnerOccupied',\n",
" 'DIS':'weightedDist',\n",
" 'RAD':'radialHighwaysAccess',\n",
" 'TAX':'propTaxRate_per10K',\n",
" 'PTRATIO':'pupilTeacherRatio',\n",
" 'LSTAT':'pctLowerStatus',\n",
" 'MEDV':'medianValue_Ks'})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "_TgUK96aodPZ"
},
"outputs": [],
"source": [
"X = renamedBostonData.drop('crimeRatePerCapita', axis = 1)\n",
"y = renamedBostonData[['crimeRatePerCapita']]\n",
"seed = 10 \n",
"test_data_size = 0.3 \n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = test_data_size, random_state = seed)\n",
"train_data = pd.concat([X_train, y_train], axis = 1)\n",
"test_data = pd.concat([X_test, y_test], axis = 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "8ihQYGRSoigK"
},
"outputs": [],
"source": [
"multiLogLinMod = smf.ols(formula=\\\n",
"'np.log(crimeRatePerCapita) ~ \\\n",
"(pctLowerStatus + radialHighwaysAccess + medianValue_Ks + nitrixOxide_pp10m)**2',\\\n",
"data=train_data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "_50rFstRor3Z"
},
"outputs": [],
"source": [
"multiLogLinModResult = multiLogLinMod.fit()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 629
},
"colab_type": "code",
"id": "6X0maK5NovBx",
"outputId": "b624fea4-257b-453e-feec-3453e3eb4d52"
},
"outputs": [],
"source": [
"print(multiLogLinModResult.summary())"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "Activity2_02.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}