# Python Scikit-Learn Module

Scikit-learn is a simple and efficient tool for predictive data analysis. It is built on NumPy, SciPy, and matplotlib.

## Installation

```bash
pip install scikit-learn
```

## Importing the Module

```python
import sklearn
```

## Basic Workflow

The typical workflow in scikit-learn involves:
1.  Loading data
2.  Splitting data into training and testing sets
3.  Initializing a model
4.  Fitting the model to the training data
5.  Predicting on new data
6.  Evaluating the model

### Loading Data

Scikit-learn comes with a few standard datasets, for example the iris and digits datasets for classification and the diabetes dataset for regression.

```python
from sklearn import datasets

iris = datasets.load_iris()
X = iris.data  # Features
y = iris.target # Labels
```

### Splitting Data

To evaluate the performance of a model, it is important to split the data into a training set and a testing set.

```python
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=42)
```

### Training a Model

Here is an example using the K-Nearest Neighbors (KNN) classifier.

```python
from sklearn.neighbors import KNeighborsClassifier

# Initialize the model
knn = KNeighborsClassifier(n_neighbors=3)

# Train the model
knn.fit(X_train, y_train)
```

### Making Predictions

```python
predictions = knn.predict(X_test)
print(predictions)
```

### Evaluating the Model

```python
from sklearn.metrics import accuracy_score

accuracy = accuracy_score(y_test, predictions)
print(f"Accuracy: {accuracy}")
```

## Regression Example

Here is a quick example using Linear Regression.

```python
from sklearn.linear_model import LinearRegression
import numpy as np

# Dummy data
X = np.array([[1], [2], [3], [4], [5]])
y = np.array([2, 4, 6, 8, 10])

model = LinearRegression()
model.fit(X, y)

print(f"Prediction for 6: {model.predict([[6]])}")
# Output: Prediction for 6: [12.]
```

[[programming/python/python]]