<jupyter_start><jupyter_text>1. Naive Bayes2. Logistic Regression3. Ada Boosting4. XG Boosting<jupyter_code>data_2017 = pd.read_csv("Portland_NAICS_2017.csv")
data_2017.shape
data_2017.head()
data_2017 = data_2017.dropna()
data_2017.shape
data_2016 = pd.read_csv("Portland_NAICS_before_2017.csv")
data_2016.shape
data_2016 = data_2016.dropna()
data_2016.shape<jupyter_output><empty_output><jupyter_text>NAIVE BAYES<jupyter_code>from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import GridSearchCV
X_train = data_2016.loc[ : , "pop":"walked_ratio"]
y_train = data_2016.loc[ : , "maxNaics_est"]
X_test = data_2017.loc[ : , "pop":"walked_ratio"]
y_test = data_2017.loc[ : , "maxNaics_est"]
#Using the GridSearchCV to find optimal estimators and leaf nodes
param_grid = {'max_depth':range(1,51), 'max_leaf_nodes':range(2,51)}
dt = DecisionTreeClassifier()
gr = GridSearchCV(dt, param_grid=param_grid, scoring='accuracy')
rs = gr.fit(X_train, y_train_emp)
print(rs.best_params_)
print(rs.score(X_test, y_test_emp))
gnb = GaussianNB()
y_pred = gnb.fit(X_train, y_train).predict(X_test)
print("Number of mislabeled points out of a total %d points : %d"
...       % (X_test.shape[0], (y_test != y_pred).sum()))
print(y_test, y_pred)
gnb.score(X_test, y_test)<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression
#Using the GridSearchCV to find optimal estimators and leaf nodes
param_grid = {'penalty':['l1', 'l2', 'elasticnet'], 'solver':['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'], 
             'max_iter':[1000]}
clf = LogisticRegression()
gr = GridSearchCV(clf, param_grid=param_grid, scoring='accuracy')
rs = gr.fit(X_train, y_train)

print(rs.best_params_)
print(rs.score(X_test, y_test))<jupyter_output>{'max_iter': 1000, 'penalty': 'l2', 'solver': 'newton-cg'}
0.5089285714285714<jupyter_text>Adaptive Boosting<jupyter_code>from sklearn.ensemble import AdaBoostClassifier
#Using the GridSearchCV to find optimal estimators and leaf nodes
param_grid = {'n_estimators':[50, 100, 150, 200]}
clf = AdaBoostClassifier()
gr = GridSearchCV(clf, param_grid=param_grid, scoring='accuracy')
rs = gr.fit(X_train, y_train)
print(rs.best_params_)
print(rs.score(X_test, y_test))<jupyter_output>{'n_estimators': 50}
0.3958333333333333<jupyter_text>XG Boosting<jupyter_code>from xgboost import XGBClassifier
param_grid = {'n_estimators':[50, 100, 150, 200], 'max_depth':[5,10,25,50,100]}
clf = XGBClassifier()
gr = GridSearchCV(clf, param_grid=param_grid, scoring='accuracy')
rs = gr.fit(X_train, y_train)
print(rs.best_params_)
print(rs.score(X_test, y_test))<jupyter_output>{'max_depth': 10, 'n_estimators': 150}
0.5625
{'fraction_non_alphanumeric': 0.14233038348082597, 'fraction_numerical': 0.061946902654867256, 'mean_word_length': 8.134680134680135, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '357007', 'license': 'MIT', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1058, 'n_words': 190, 'path': 'Dev_Ram_portland_NAICS_modelling.ipynb', 'repo_name': 'kronellenfitsch/Portland_CARTO_notebook', 'size': '2712'}