Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_plot_corr/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_plot_corr/__pycache__/build.cpython-36.pyc
Binary file not shown.
14 changes: 10 additions & 4 deletions q01_plot_corr/build.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# %load q01_plot_corr/build.py
# Default imports
import pandas as pd
from matplotlib.pyplot import yticks, xticks, subplots, set_cmap
plt.switch_backend('agg')
import matplotlib.pyplot
#plt.switch_backend('agg')
data = pd.read_csv('data/house_prices_multivariate.csv')
#% matplotlib inline


# Write your solution here:
def plot_corr(data, size=11):
corr = data.corr()
fig, ax = subplots(figsize=(size, size))
set_cmap("YlOrRd")
set_cmap('YlOrRd')
ax.matshow(corr)
xticks(range(len(corr.columns)), corr.columns, rotation=90)
yticks(range(len(corr.columns)), corr.columns)
return ax





Binary file modified q01_plot_corr/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_plot_corr/tests/__pycache__/test_q01_plot_corr.cpython-36.pyc
Binary file not shown.
Binary file modified q02_best_k_features/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_best_k_features/__pycache__/build.cpython-36.pyc
Binary file not shown.
23 changes: 21 additions & 2 deletions q02_best_k_features/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
# %load q02_best_k_features/build.py
# Default imports

import pandas as pd

import numpy as np
data = pd.read_csv('data/house_prices_multivariate.csv')

from sklearn.feature_selection import SelectPercentile
from sklearn.feature_selection import f_regression

def percentile_k_features(df,k = 20):
X = df.drop(['SalePrice'], axis = 1)
y = df['SalePrice']

#regression model and transform method on predictors and target
selector = SelectPercentile(f_regression, k)
X_new = selector.fit_transform(X, y)


#list of best features with implementation of k percentile method
featurelist = list(X.columns.values[np.argsort(selector.scores_)
[-1:-X_new.shape[1]-1:-1]])

return featurelist




#percentile_k_features(df, 20)

# Write your solution here:

Binary file modified q02_best_k_features/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file added q03_rf_rfe/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added q03_rf_rfe/__pycache__/build.cpython-36.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions q03_rf_rfe/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q03_rf_rfe/build.py
# Default imports
import pandas as pd

Expand All @@ -9,3 +10,18 @@

# Your solution code here

def rf_rfe(df):
X = df.drop('SalePrice',axis=1)
y = df['SalePrice']

model = RandomForestClassifier()
rfe = RFE(model,n_features_to_select=len(X.columns)/2)
rfe = rfe.fit(X,y)

return list(X.columns[rfe.support_])



rf_rfe(data)


Binary file added q03_rf_rfe/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions q04_select_from_model/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q04_select_from_model/build.py
# Default imports
from sklearn.feature_selection import SelectFromModel
from sklearn.ensemble import RandomForestClassifier
Expand All @@ -8,3 +9,19 @@


# Your solution code here
def select_from_model(data):
X = data.drop('SalePrice',axis=1)
y = data['SalePrice']

model = RandomForestClassifier()

sfm = SelectFromModel(model)
sfm.fit_transform(X,y)

feature_name = list(X.columns[sfm.get_support()])

return feature_name

select_from_model(data)


Binary file not shown.
Binary file not shown.