Skip to content

Instantly share code, notes, and snippets.

@jackty9
jackty9 / F_regression_scikit_learn_jacktan.py
Last active September 13, 2020 13:44
Feature_Selection_Python_Numerical_Input
from sklearn.datasets import make_regression
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_regression
import pandas as pd
# generate dataset
X, y = make_regression(n_samples=100, n_features=50, n_informative=10)
#assign column names
col_list = ['col_' + str(x) for x in range(0,50)]
#create a dataframe table
@jackty9
jackty9 / F_classif_scikit_learn_jacktan.py
Last active September 13, 2020 12:00
Feature_Selection_Python_Numerical_Input
from sklearn.datasets import make_classification
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_classif
import pandas as pd
# generate dataset
X, y = make_classification(n_samples=100, n_features=50, n_informative=10)
#assign column names
col_list = ['col_' + str(x) for x in range(0,50)]
#create a dataframe table
@jackty9
jackty9 / chi2_scikit_learn_jacktan.py
Last active September 13, 2020 13:32
Feature_Selection_Python_categorical_Input
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
import pandas as pd
#import raw data, data can be found in Github directory
#https://github.com/jackty9/Feature_Selection_in_Python/blob/master/car_data.csv
df = pd.read_csv("car_data.csv")
X = df1.iloc[:,0:5]
X = pd.get_dummies(X)
y = df1.iloc[:,-1]
@jackty9
jackty9 / Mutual_Info_scikit_learn_jacktan.py
Created September 13, 2020 13:33
Feature_Selection_Python_categorical_Input
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import mutual_info_classif
import pandas as pd
#import raw data, data can be found in Github directory
#https://github.com/jackty9/Feature_Selection_in_Python/blob/master/car_data.csv
df1 = pd.read_csv("car_data.csv")
X = df1.iloc[:,0:5]
X = pd.get_dummies(X)
y = df1.iloc[:,-1]
@jackty9
jackty9 / RFE_sklearn_jacktan.py
Last active October 13, 2020 22:20
Feature_Selection_Wrapper_Methods
#Load needed libraries
from sklearn.datasets import load_boston
from sklearn.feature_selection import RFE
from sklearn.linear_model import LinearRegression
import pandas as pd
import numpy as np
# load_boston() sklearn dataset to boston
boston = load_boston()
@jackty9
jackty9 / SFS_mlxtend_jacktan.py
Created October 8, 2020 22:00
Feature_Selection_Wrapper_Methods
#Load needed libraries
from sklearn.datasets import load_boston
from mlxtend.feature_selection import SequentialFeatureSelector as SFS
from sklearn.linear_model import LinearRegression
import pandas as pd
import numpy as np
# load_boston() sklearn dataset to boston
boston = load_boston()
@jackty9
jackty9 / SFFS_mlxtend_jacktan.py
Created October 11, 2020 13:08
Feature_Selection_Wrapper_Methods
#Load needed libraries
from sklearn.datasets import load_boston
from mlxtend.feature_selection import SequentialFeatureSelector as SFS
from sklearn.linear_model import LinearRegression
import pandas as pd
import numpy as np
# load_boston() sklearn dataset to boston
boston = load_boston()
@jackty9
jackty9 / plot_SFS_mlxtend_jacktan.py
Created October 13, 2020 21:28
Feature_Selection_Wrapper_Methods
#Load needed libraries
from mlxtend.feature_selection import SequentialFeatureSelector as SFS
from mlxtend.plotting import plot_sequential_feature_selection as plot_sfs
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt
#import and prepare data
boston = load_boston()
X, y = boston.data, boston.target
@jackty9
jackty9 / random_undersampling_imblearn.py
Last active November 12, 2020 08:25
Dealing_imbalanced_data_in_Python
#PART 1
# import random undersampling and other necessary libraries
from collections import Counter
from imblearn.under_sampling import RandomUnderSampler
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
@jackty9
jackty9 / SMOTE_oversampling_imblearn.py
Last active November 12, 2020 08:25
Dealing_imbalanced_data_in_Python
#PART 1
# import SMOTE oversampling and other necessary libraries
from collections import Counter
from imblearn.over_sampling import SMOTE
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)