<jupyter_start><jupyter_text>Combined methods for stock predictions  Importing the libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd<jupyter_output><empty_output><jupyter_text>Importing the dataset<jupyter_code>train = pd.read_csv("train.csv", engine='python',nrows=50000)
features = [col for col in list(train.columns) if 'feature' in col]
train = train[train['weight'] != 0]
train['action'] = (train['resp'].values > 0).astype(int)<jupyter_output><empty_output><jupyter_text>Taking care of missing data<jupyter_code># from sklearn.impute import SimpleImputer
# imputer_o = SimpleImputer(missing_values=np.nan, strategy='mean')
# imputer_t = SimpleImputer(missing_values=np.nan, strategy='mean')#, fill_value=f_mean_t
# train_o = train[train['action'] == 0]
# train_t = train[train['action'] == 1]
# imputer_o.fit(train_o)
# imputer_t.fit(train_t)
# train_o = imputer_o.transform(train_o)
# train_t = imputer_t.transform(train_t)
# # f_mean_o = train_o.mean()
# # f_mean_t = train_t.mean()
# # train_o = train_o.fillna(f_mean_o)
# # train_t = train_t.fillna(f_mean_t)
# print(len(train), len(train_t))
# train = np.concatenate(train_o[1:,:] , train_t[1:,:])
# print(len(train))
# # train = train.fillna(f_mean)
train = train.dropna()
# from sklearn.impute import SimpleImputer
# imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
# imputer.fit(X)
# X = imputer.transform(X)#[:, 1:3]<jupyter_output><empty_output><jupyter_text>create X and y<jupyter_code>X = train.loc[:, features]
y = train.loc[:, 'action']
del train
X = np.array(X)
y = np.array(y)<jupyter_output><empty_output><jupyter_text>Splitting the dataset into the Training set and Test set<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)<jupyter_output><empty_output><jupyter_text>Feature Scaling<jupyter_code>from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)<jupyter_output><empty_output><jupyter_text>Applying Kernel PCA<jupyter_code>from sklearn.decomposition import KernelPCA
kpca = KernelPCA(n_components = 5, kernel = 'rbf')
X_train = kpca.fit_transform(X_train)
X_test = kpca.transform(X_test)<jupyter_output><empty_output><jupyter_text>Training the Logistic Regression model on the Training set<jupyter_code>from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state = 0)
classifier.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Making the Confusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix, accuracy_score
y_pred = classifier.predict(X_test)
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)<jupyter_output><empty_output><jupyter_text>Training the Random Forest Classification model on the Training set<jupyter_code>from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(n_estimators = 20, criterion = 'entropy', random_state = 0)
classifier.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Predicting the Test set results<jupyter_code>y_pred = classifier.predict(X_test)
print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))<jupyter_output><empty_output><jupyter_text>Making the Confusion Matrix<jupyter_code>from sklearn.metrics import confusion_matrix, accuracy_score
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12149013066444259, 'fraction_numerical': 0.006672226855713094, 'mean_word_length': 9.30945558739255, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '354567', 'license': 'Apache-2.0', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1332, 'n_words': 227, 'path': 'dim_reduction_with_random_for.ipynb', 'repo_name': 'Nijaoui-Wassim/Jane-Street-Market-Predictions', 'size': '3597'}