<jupyter_start><jupyter_text>Generating Data  Generating data for regression<jupyter_code>from sklearn.datasets import make_regression

X, y = make_regression(**{
    'n_samples': 1000, 
    'n_features': 50, 
    'n_informative': 10, 
    'n_targets': 1, 
    'bias': 5.3, 
    'random_state': 37
})

print(f'X shape = {X.shape}, y shape {y.shape}')
from sklearn.linear_model import Lasso
from sklearn.metrics import explained_variance_score

lasso = Lasso()
lasso.fit(X, y)

explained_variance_score(y, lasso.predict(X))<jupyter_output><empty_output><jupyter_text>Generating data for classification<jupyter_code>from sklearn.datasets import make_classification

X, y = make_classification(**{
    'n_samples': 2000, 
    'n_features': 20, 
    'n_informative': 2, 
    'n_redundant': 2, 
    'n_repeated': 0, 
    'n_classes': 2, 
    'n_clusters_per_class': 2, 
    'random_state': 37
})

print(f'X shape = {X.shape}, y shape {y.shape}')
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score

rf = RandomForestClassifier(n_estimators=2)
rf.fit(X, y)

roc_auc_score(y, rf.predict(X))<jupyter_output><empty_output><jupyter_text>Generating data for multilabel classification<jupyter_code>from sklearn.datasets import make_multilabel_classification

X, Y = make_multilabel_classification(**{
    'n_samples': 2000, 
    'n_features': 20, 
    'n_classes': 5, 
    'n_labels': 2, 
    'length': 50, 
    'allow_unlabeled': False, 
    'sparse': False, 
    'return_indicator': 'dense', 
    'return_distributions': False, 
    'random_state': 37
})

print(f'X shape = {X.shape}, Y shape {Y.shape}')
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score

rf = RandomForestClassifier(n_estimators=2)
rf.fit(X, Y)

roc_auc_score(Y, rf.predict(X))
import numpy as np
from sklearn.metrics import coverage_error, \
    label_ranking_average_precision_score, \
    label_ranking_loss

probs = rf.predict_proba(X)
n_cols = len(probs)
n_rows = probs[0].shape[0]

Y_preds = np.array([[probs[c][r][1] for c in range(n_cols)] for r in range(n_rows)])

for metric in [coverage_error, label_ranking_average_precision_score, label_ranking_loss]:
    print(f'{metric(Y, Y_preds):.5f} : {metric.__name__}')<jupyter_output>2.58750 : coverage_error
0.93136 : label_ranking_average_precision_score
0.09871 : label_ranking_loss<jupyter_text>Generating data for clustering<jupyter_code>from sklearn.datasets import make_blobs

X, y = make_blobs(**{
    'n_samples': 3000, 
    'n_features': 15, 
    'centers': 3, 
    'cluster_std': 1.0,
    'center_box': (-10.0, 10.0),
    'random_state': 37
})

print(f'X shape = {X.shape}, y shape {y.shape}')
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score

km = KMeans(n_clusters=3, random_state=37)
km.fit(X)

silhouette_score(X, km.predict(X))<jupyter_output><empty_output><jupyter_text>Available datasets  Datasets for regression  California housing<jupyter_code>from sklearn.datasets import fetch_california_housing

X, y = fetch_california_housing(return_X_y=True)<jupyter_output>Downloading Cal. housing from https://ndownloader.figshare.com/files/5976036 to /root/scikit_learn_data<jupyter_text>Diabetes<jupyter_code>from sklearn.datasets import load_diabetes

X, y = load_diabetes(return_X_y=True)<jupyter_output><empty_output><jupyter_text>Linnerud<jupyter_code>from sklearn.datasets import load_linnerud

X, y = load_linnerud(return_X_y=True)<jupyter_output><empty_output><jupyter_text>Datasets for classification  Newsgroup<jupyter_code>from sklearn.datasets import fetch_20newsgroups_vectorized

T_X, T_y = fetch_20newsgroups_vectorized(subset='train', return_X_y=True)
V_X, V_y = fetch_20newsgroups_vectorized(subset='test', return_X_y=True)<jupyter_output>Downloading 20news dataset. This may take a few minutes.
Downloading dataset from https://ndownloader.figshare.com/files/5975967 (14 MB)<jupyter_text>Covertype<jupyter_code>from sklearn.datasets import fetch_covtype

X, y = fetch_covtype(return_X_y=True)<jupyter_output>Downloading https://ndownloader.figshare.com/files/5976039<jupyter_text>KDD Cup 1999<jupyter_code>from sklearn.datasets import fetch_kddcup99

X, y = fetch_kddcup99(subset='http', return_X_y=True)<jupyter_output>Downloading https://ndownloader.figshare.com/files/5976042<jupyter_text>RCV1<jupyter_code>from sklearn.datasets import fetch_rcv1

T_X, T_y = fetch_rcv1(subset='train', return_X_y=True)
V_X, V_y = fetch_rcv1(subset='test', return_X_y=True)<jupyter_output>Downloading https://ndownloader.figshare.com/files/5976069
Downloading https://ndownloader.figshare.com/files/5976066
Downloading https://ndownloader.figshare.com/files/5976063
Downloading https://ndownloader.figshare.com/files/5976060
Downloading https://ndownloader.figshare.com/files/5976057
Downloading https://ndownloader.figshare.com/files/5976048<jupyter_text>Digits<jupyter_code>from sklearn.datasets import load_digits

X, y = load_digits(return_X_y=True)<jupyter_output><empty_output><jupyter_text>Iris<jupyter_code>from sklearn.datasets import load_iris

X, y = load_iris(return_X_y=True)<jupyter_output><empty_output><jupyter_text>Wine<jupyter_code>from sklearn.datasets import load_wine

X, y = load_wine(return_X_y=True)<jupyter_output><empty_output><jupyter_text>OpenML<jupyter_code>from sklearn.datasets import fetch_openml

mice = fetch_openml(name='miceprotein', version=4)
X, y = mice.data, mice.target

print(mice.DESCR)<jupyter_output>**Author**: <NAME>, <NAME>, <NAME>  
**Source**: [UCI](https://archive.ics.uci.edu/ml/datasets/Mice+Protein+Expression) - 2015   
**Please cite**: <NAME>, <NAME>, <NAME>J (2015) Self-Organizing Feature Maps Identify Proteins Critical to Learning in a Mouse Model of Down Syndrome. PLoS ONE 10(6): e0129126.

Expression levels of 77 proteins measured in the cerebral cortex of 8 classes of control and Down syndrome mice exposed to context fear conditioning, a task used to assess associative learning.

The data set consists of the expression levels of 77 proteins/protein modifications that produced detectable signals in the nuclear fraction of cortex. There are 38 control mice and 34 trisomic mice (Down syndrome), for a total of 72 mice. In the experiments, 15 measurements were registered of each protein per sample/mouse. Therefore, for control mice, there are 38x15, or 570 measurements, and for trisomic mice, there are 34x15, or 510 measurements. Th[...]
{'fraction_non_alphanumeric': 0.1093725793958172, 'fraction_numerical': 0.03408210689388071, 'mean_word_length': 6.463583815028902, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 60, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '148121', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 2552, 'n_tokens_neox': 2298, 'n_words': 481, 'path': 'sphinx/scikit-intro/source/generate-samples.ipynb', 'repo_name': 'oneoffcoder/books', 'size': '6496'}