Back to all postsAI/ML

Introduction to Machine Learning with Python

Arsene Indamutsa
December 18, 20241 min read
Introduction to Machine Learning with Python

Get started with machine learning using Python, scikit-learn, and TensorFlow.

Introduction to Machine Learning with Python

Machine learning is transforming industries. Here's your starting point.

What is Machine Learning?

ML enables computers to learn patterns from data without explicit programming.

Types of Learning

  1. Supervised Learning: Learn from labeled data
  2. Unsupervised Learning: Find patterns in unlabeled data
  3. Reinforcement Learning: Learn through trial and error

Your First ML Model

from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

# Prepare 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(n_estimators=100)
model.fit(X_train, y_train)

# Evaluate
predictions = model.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(f"Accuracy: {accuracy:.2f}")

Deep Learning with TensorFlow

import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

Conclusion

Start with simple models, understand the fundamentals, then explore deep learning. The journey is rewarding!

Tags

#machine-learning#python#tensorflow#data-science

Enjoyed this article?

Share it with your friends and colleagues.