<jupyter_start><jupyter_text>Objectives* Consider only two features of the dataset obtained after t-sne* Find out best performing value of perplexity for t-sne using cross-validation* Use linear model with no calibration vs non linear model to see how well these perform<jupyter_code>def get_training_set(train):
    X = train[train.columns.drop('Activity')]
    y = train.Activity
    
    return X, y

X, y = get_training_set(train)
Xtest = test
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, test_size=0.3, random_state=44)<jupyter_output><empty_output><jupyter_text>Cross validation<jupyter_code>def get_cross_val_scores_by_perplexity(X, y, clf):
    skf = StratifiedKFold(y, n_folds=3, shuffle=True, random_state=43)
    perplexity = [50, 75, 100]
    errors = []
    
    for p in perplexity:
        tsne = TSNE(n_components=2, perplexity=p)
        Xhat = tsne.fit_transform(X)
        
        cv_scores = cross_val_score(clf, Xhat, y, scoring='log_loss', cv=skf, n_jobs=-1)
        errors.append(cv_scores.mean())
    
    perplexity = np.array(perplexity)
    errors = np.array(errors)
    
    return perplexity, errors
perplexity, errors = get_cross_val_scores_by_perplexity(X, y, LogisticRegression(C=1.))
errors = map(abs, errors)
plt.scatter(perplexity, errors, color='b', alpha=0.5)
plt.xlabel('Perplexity')
plt.ylabel('Log Loss');
perplexity, errors = get_cross_val_scores_by_perplexity(X, y, RandomForestClassifier(n_jobs=-1))
errors = map(abs, errors)
plt.scatter(perplexity, errors, color='b', alpha=0.5)
plt.xlabel('Perplexity')
plt.ylabel('Log Loss');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11800860479409957, 'fraction_numerical': 0.013521819299323909, 'mean_word_length': 5.007380073800738, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '668563', 'license': 'MIT', 'n_tokens_mistral': 620, 'n_tokens_neox': 589, 'n_words': 128, 'path': 'Kaggle-Competitions/Predict-Bio-Response/Predict-Bio-Response-Model-Building.ipynb', 'repo_name': 'gopala-kr/ds-notebooks', 'size': '1627'}