Scikit-learn: machine learning in Python
Scikit-learn is a popular machine learning library for Python that provides various tools for data analysis and modeling. It is built on top of NumPy, SciPy, and matplotlib and is used for tasks such as classification, regression, clustering, and dimensionality reduction.
Installation
Scikit-learn can be installed using pip:
pip install scikit-learn
Example: Classification with Support Vector Machines
Here's an example of using Scikit-learn for classification with support vector machines (SVMs):
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
# Load the iris dataset
iris = datasets.load_iris()
# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2)
# Create an SVM classifier with a linear kernel
clf = SVC(kernel='linear')
# Train the classifier on the training set
clf.fit(X_train, y_train)
# Test the classifier on the testing set and print the accuracy
y_pred = clf.predict(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
In this example, we load the iris dataset and split it into training and testing sets. We then create an SVM classifier with a linear kernel, train it on the training set, and test it on the testing set. Finally, we print the accuracy of the classifier.
Conclusion
Scikit-learn is a powerful machine learning library for Python that provides a wide range of tools for data analysis and modeling. Its easy-to-use interface and extensive documentation make it a popular choice for both beginners and experts in the field.