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.
10 changes: 9 additions & 1 deletion q01_plot_corr/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# %load q01_plot_corr/build.py
# Default imports
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.pyplot import yticks, xticks, subplots, set_cmap
plt.switch_backend('agg')
data = pd.read_csv('data/house_prices_multivariate.csv')
Expand All @@ -9,8 +11,14 @@
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)
plt.show()
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.
17 changes: 17 additions & 0 deletions q02_best_k_features/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# %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')

Expand All @@ -9,4 +11,19 @@


# Write your solution here:
def percentile_k_features(df,k=20):
X = df.iloc[:,:-1]
y= df.iloc[:,-1]
selection = SelectPercentile(f_regression, percentile=k)
x_features = selection.fit_transform(X, y)
columns = np.asarray(X.columns.values)
support = np.asarray(selection.get_support())
columns_with_support = columns[support]
return list(columns_with_support)







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.
21 changes: 21 additions & 0 deletions q03_rf_rfe/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# %load q03_rf_rfe/build.py
# Default imports
import pandas as pd
import numpy as np

data = pd.read_csv('data/house_prices_multivariate.csv')

Expand All @@ -8,4 +10,23 @@


# Your solution code here
def rf_rfe(df):
rfe = RandomForestClassifier()
X,y = df.iloc[:,:-1],df.iloc[:,-1]

selector = RFE(rfe, step=1)
selector = selector.fit(X, y)

arr_columns = np.array(df.columns)
arr = np.select([selector.get_support()],[arr_columns[:-1]] )
return arr[arr!=0].tolist()










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.
15 changes: 15 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,17 @@


# Your solution code here
def select_from_model(df):

X = df.iloc[:,:-1]
y = df.iloc[:,-1]
rf = RandomForestClassifier()
slm = SelectFromModel(rf)
slm.fit(X,y)
slm.get_support()
columns = np.array(df.columns[:-1])
return columns[slm.get_support()[:]].tolist()




Binary file not shown.
Binary file not shown.