Machine Learning with Python
Explore the fascinating world of Machine Learning using Python. This tutorial will cover essential machine learning concepts, algorithms, and practical implementations using libraries like Scikit-learn and TensorFlow/Keras. You'll learn how to preprocess data, build and evaluate models, and make predictions.
Key topics include:
- Supervised vs. Unsupervised Learning
- Linear Regression, Logistic Regression
- Decision Trees and Random Forests
- Introduction to Neural Networks
Linear Regression Example
Linear regression is a basic and commonly used type of predictive analysis. The overall idea of regression is to examine two things: (1) does a set of predictor variables do a good job in predicting an outcome (dependent) variable? (2) Which variables in particular are significant predictors of the outcome variable, and in what way do they — indicated by the magnitude and sign of their coefficients — impact the outcome variable?
import numpy as np
from sklearn.linear_model import LinearRegression
# Sample data
X = np.array([1, 2, 3, 4, 5]).reshape(-1, 1) # Features
y = np.array([2, 4, 5, 4, 5]) # Target
# Create and fit model
model = LinearRegression()
model.fit(X, y)
# Make prediction
y_pred = model.predict(np.array([6]).reshape(-1, 1))
print(f"Prediction for X=6: {y_pred[0]:.2f}")
Decision Trees
A decision tree is a flowchart-like structure in which each internal node represents a "test" on an attribute, each branch represents the outcome of the test, and each leaf node represents a class label (decision taken after computing all attributes).
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_iris
# Load iris dataset
iris = load_iris()
X, y = iris.data, iris.target
# Create and fit model
model = DecisionTreeClassifier()
model.fit(X, y)
# Predict
print(f"Prediction for a new sample: {model.predict([[5.1, 3.5, 1.4, 0.2]])}")
Unleash the power of data with Machine Learning!