#### 1.
Image Recognition:
Machine learning systems can classify images by identifying patterns within them. For instance, when you upload a photo to an app like Google Photos, the system recognizes the content of the image (people, cars, animals) based on pre-trained models.
Code:
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import numpy as np
# Load the pre-trained model
model = load_model('model.h5')
# Load the image for classification
img = image.load_img('test_image.jpg', target_size=(150, 150))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
# Predict the class of the image
prediction = model.predict(img_array)
print(f"Model Prediction: {prediction}")
#### 2.
Sales Prediction:
Companies use machine learning to analyze past sales data and predict future trends. This helps in making strategic decisions like product stocking or financial planning.
Code:
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import numpy as np
# Example sales data
sales_data = np.array([[1, 100], [2, 150], [3, 200], [4, 250]]) # month and sales
X = sales_data[:, 0].reshape(-1, 1) # input: month
y = sales_data[:, 1] # output: sales
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# Create Linear Regression model
model = LinearRegression()
model.fit(X_train, y_train)
# Predict sales for the fifth month
predicted_sales = model.predict([[5]])
print(f"Predicted sales for month 5: {predicted_sales}")
#### 3.
Spam Detection:
Email systems use machine learning to detect spam messages from regular emails. The system learns from previous classified emails to improve its accuracy.
Code:
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
# Training data (regular and spam emails)
emails = ["Congratulations, you've won a prize!", "Meeting tomorrow at 10am", "Cheap products available now"]
labels = [1, 0, 1] # 1 means spam, 0 means regular email
# Convert texts to numerical data
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(emails)
# Train the model
model = MultinomialNB()
model.fit(X, labels)
# Test the model
test_email = vectorizer.transform(["Win a free vacation now!"])
prediction = model.predict(test_email)
print(f"Email Prediction: {'Spam' if prediction[0] == 1 else 'Regular email'}")
### Types of Machine Learning:
#### 1.
Supervised Learning:
In this type, the model is trained using data that includes both inputs and the correct outputs. For example, the model could be trained to classify images or email messages.
#### 2.
Unsupervised Learning:
In this type, the system is not provided with the correct answers. Instead, the model looks for patterns in the data, like clustering similar images.
#### 3.
Reinforcement Learning:
This is similar to learning from trial and error, where the system learns by being rewarded for correct decisions and penalized for mistakes.
---
Both versions are enhanced for clarity and engagement, with added code examples to illustrate the concepts for beginners.
:)