So I was following an ML lecture and this is the entire code and this is the dataset (https://archive.ics.uci.edu/dataset/159/magic+gamma+telescope) I was using.
When I run the code locally on Jupyter notebook in my machine at first the error showed up with the plot but there’s no plotting, when I ran the cell again the error is not shown again but the plots are the same
This is the code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# the attributes
column_names = ["fLength", "fWidth", "fSize", "fConc", "fConc1",
"fAsym", "fM3Long", "fM3Trans", "fAlpha", "fDist", "class"]
# dataframe
df = pd.read_csv("magic04.data", names=column_names)
df.head()
# changing all 'g' to 1 and 'h' to 0
df["class"] = (df["class"] == "g").astype(int)
df.head()
for label in column_names[:-1]: # plotting first 10 cols
# Filters the DataFrame df to include only rows where the value in the "class" column is equal to 1.
# So, it selects only the rows where the class is labeled as "gamma"
plt.hist(df[df["class"]==1][label], bins=100, color='red', label="gamma", alpha=0.7, density=True)
plt.hist(df[df["class"]==0][label], bins=100, color='green', label="beta", alpha=0.7, density=True)
plt.title(label)
plt.ylabel("probability")
plt.xlabel(label)
plt.legend()
plt.show()
This is what I’m getting:
sample
The weird thing is, the plot and all works perfectly fine in google collab with the same code I don’t know why. So maybe I’m missing a library or something?
It will be great if anyone could help me out here.
I tried googling the issue and asking AIs but no luck
This is the desired output (taken from google collab)
expected_result
Jack Rayes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.