AI & Machine Learning

Introduction to Machine Learning with Python

📅 December 05, 2025 ⏱️ 1 min read 👁️ 6 views 🏷️ AI & Machine Learning

Machine Learning enables computers to learn from data without being explicitly programmed. Let's explore the basics with Python.

Linear Regression Example


from sklearn.linear_model import LinearRegression
import numpy as np

# Sample data
X = np.array([[1], [2], [3], [4], [5]])
y = np.array([2, 4, 6, 8, 10])

# Create and train model
model = LinearRegression()
model.fit(X, y)

# Make predictions
prediction = model.predict([[6]])
print(f"Predicted value: {prediction[0]}")  # Output: 12.0
print(f"Coefficient: {model.coef_[0]}")  # Output: 2.0

Classification with Decision Trees


from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split

# Sample dataset
X = [[0, 0], [1, 1], [2, 2], [3, 3]]
y = [0, 0, 1, 1]

# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)

# Train model
clf = DecisionTreeClassifier()
clf.fit(X_train, y_train)

# Evaluate
accuracy = clf.score(X_test, y_test)
print(f"Accuracy: {accuracy * 100}%")
🏷️ Tags:
machine learning python sklearn ai tutorial

📚 Related Articles