0% found this document useful (0 votes)
12 views3 pages

SOURCE CODE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

SOURCE CODE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SOURCE CODE

import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as mse
import seaborn as sns
import matplotlib.pyplot as plt

dataset = pd.read_csv("forestfires.csv")
print(dataset.isnull().sum())

features = ["FFMC", "temp", "DC", "RH", "wind"]


X = dataset[features]
y = dataset["DMC"]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y)
model = LinearRegression()
print(model.fit(X_train, y_train))
y_pred=model.predict(X_test)
print("MSE =", mse(y_pred, y_test))
print(y_pred[:5])
print(y_test.head())
# Evaluate the model
train_score = model.score(X_train, y_train) * 100
test_score = model.score(X_test, y_test) * 100
print(f"Training Score: {train_score:.2f}%")
print(f"Test Score: {test_score:.2f}%")

#To create Heat Map


u=dataset.drop(["month","day"],axis="columns")
correlation_matrix = u.corr()
plt.figure(figsize=(10, 8))
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm',
fmt='.2f', linewidths=0.5)
plt.title('Heatmap of Correlation Matrix')
plt.show()

#To create box plot


column_name = 'wind'
plt.figure(figsize=(10, 6))
sns.boxplot(data=dataset, x=column_name)
plt.title(f'Box Plot of {column_name}')
plt.xlabel(column_name)
plt.show()

#To create scatter plot


x_column = 'FFMC'
y_column = 'DMC'
plt.figure(figsize=(8, 6))
plt.scatter(dataset[x_column], dataset[y_column], color='blue',
alpha=0.7,
edgecolor='k')
plt.xlabel(x_column)
plt.ylabel(y_column)
plt.title(f'Scatter Plot of {x_column} vs {y_column}')
plt.grid(True)
plt.show()

#To create Pair plot


columns_to_plot = ['DMC', 'wind', 'FFMC','ISI']
df_subset = dataset[columns_to_plot]
sns.pairplot(df_subset, diag_kind='kde', markers='o', corner=False)
plt.suptitle('Pair Plot of Selected Attributes', y=1.02)
plt.show()

You might also like