<jupyter_start><jupyter_text>Tests of the Light GBM techniqueInitial source: https://medium.com/@pushkarmandot/https-medium-com-pushkarmandot-what-is-lightgbm-how-to-implement-it-how-to-fine-tune-the-parameters-60347819b7fc<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Data preprocessing<jupyter_code>dataset = pd.read_csv('../input/Social_Network_Ads.csv')
dataset.head()
X = dataset.iloc[:, [2, 3]].values
y = dataset.iloc[:, 4].values

# Splitting the dataset into the Training set and Test set
from sklearn.cross_validation import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 1)
x_train.mean(axis=0)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()

sc.get_params()
x_train = sc.fit_transform(x_train)
print(x_train.mean(axis=0), x_train.std(axis=0))
# pay attention to 10^-16 it's almost ~0
print(x_test.mean(), x_test.std())
x_test = sc.transform(x_test)
print(x_test.mean(), x_test.std())<jupyter_output>0.14647424882649773 1.0635012876111132<jupyter_text>LGBM<jupyter_code>import lightgbm as lgb
d_train = lgb.Dataset(x_train, label=y_train)
params = {}
params['learning_rate'] = 0.003
params['boosting_type'] = 'gbdt'
params['objective'] = 'binary'
params['metric'] = 'binary_logloss'
params['sub_feature'] = 0.5
params['num_leaves'] = 10
params['min_data'] = 50
params['max_depth'] = 10
clf = lgb.train(params, d_train, 100)
#Prediction
y_pred=clf.predict(x_test)
#convert into binary values
for i in range(0,100):
    if(y_pred[i] >= 0.5):       # setting threshold to .5
       y_pred[i] = 1
    else:  
       y_pred[i] = 0
#count = int(np.sum(x_test[:,1]) / np.mean(x_test[:,1]))
#count
# Checking results

#Confusion matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
cm
#Accuracy
from sklearn.metrics import accuracy_score
accuracy=accuracy_score(y_pred, y_test)
accuracy<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13424791768740812, 'fraction_numerical': 0.04164625183733464, 'mean_word_length': 6.292857142857143, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '35031', 'license': 'MIT', 'n_tokens_mistral': 829, 'n_tokens_neox': 778, 'n_words': 153, 'path': 'src/.ipynb_checkpoints/kernel-checkpoint.ipynb', 'repo_name': 'DrDarbin/lightgbm-test-purchases', 'size': '2041'}