Introduction to Machine Learning
Machine Learning (ML) is a subset of Artificial Intelligence (AI) that allows systems to learn and improve from experience without being explicitly programmed. Here’s a basic example:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
# Load dataset
iris = load_iris()
X, y = iris.data, iris.target
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train model
model = RandomForestClassifier()
model.fit(X_train, y_train)
# Test model
y_pred = model.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, y_pred)}")
This code demonstrates how to load a dataset, split it into training and testing sets, and train a Random Forest Classifier to make predictions.