1. Home
  2. /
  3. Scikit-learn
  4. /
  5. Train-Test Split Example

Train-Test Split Example - Scikit-learn Typing CST Test

Loading…

Train-Test Split Example — Scikit-learn Code

Splits dataset into training and testing sets.

from sklearn.model_selection import train_test_split
import numpy as np

x = np.arange(10).reshape((5,2))
y = np.array([0,1,0,1,0])

x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.4,random_state=42)
print('X_train:', x_train)
print('X_test:', x_test)

Scikit-learn Language Guide

Scikit-learn is an open-source Python library for machine learning that provides simple and efficient tools for data mining, analysis, and predictive modeling, built on top of NumPy, SciPy, and Matplotlib.

Primary Use Cases

  • ▸Supervised learning: regression and classification
  • ▸Unsupervised learning: clustering, dimensionality reduction
  • ▸Data preprocessing and feature engineering
  • ▸Model evaluation and selection
  • ▸Building ML pipelines for production-ready workflows

Notable Features

  • ▸Wide variety of ML algorithms
  • ▸Pipeline API for chaining preprocessing and models
  • ▸Cross-validation and hyperparameter tuning tools
  • ▸Integration with NumPy, Pandas, and Matplotlib
  • ▸Extensive documentation and examples

Origin & Creator

Scikit-learn was created by David Cournapeau in 2007 as a Google Summer of Code project, and later developed by a community of contributors to become a widely adopted ML library in Python.

Industrial Note

Scikit-learn is widely used in industry and research for predictive modeling, data analysis, prototyping machine learning workflows, and teaching ML concepts.

More Scikit-learn Typing Exercises

Scikit-learn Simple Linear RegressionScikit-learn Logistic RegressionScikit-learn Decision Tree ClassifierScikit-learn K-Nearest NeighborsScikit-learn Support Vector MachineScikit-learn Random Forest ClassifierScikit-learn Naive Bayes ClassifierScikit-learn StandardScaler ExampleScikit-learn PCA Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher