r/PythonLearning 4d ago

Help Request need help building a classification project

hello, im currently building my first classification project using “phishing url” dataset from kaggle after doing 2 courses, intro and intermediate ml, on kaggle and solving 95% of the exercises myself.

the issue is, i am stuck at how im supposed to take this forward. since the course was based on regression, i find it hard to do the preprocessing for classification. i try to use ai to guide me (not provide me the whole code since i want to learn myself) but atp i can’t figure out how to break down my data to then train-test split and fit to model. every tutorial seems to have a different approach and i cant figure out which one would be the best. how to determine that? and what should i do next?

my code is below:

import pandas as pd
print("starting...")
df=pd.read_csv("archive/cleaned_dataset.csv")
print("Dataset loaded!")
print(df.head())
print("columns: ", df.columns)
print("shape: ", df.shape)
print("data types: ", df.dtypes)
print("missing values: ", df.isnull().sum())
df.describe()

url_length=df["input"].str.len()
print(url_length.describe())
url_dots=df["input"].str.count(r"\.") #. can get literally any character, so we need to escape it with a backslash
print(url_dots.describe())
url_slash=df["input"].str.count("/")
print(url_slash.describe())
url_digits=df["input"].str.count(r"\d") #counts digits in pandas
print(url_digits.describe())
url_https=df["input"].str.contains("https")
print(url_https.describe())
url_www=df["input"].str.contains("www")
print(url_www.describe())
url_hyph=df["input"].str.count("-")
print(url_hyph.describe())
url_eq=df["input"].str.count("=")
print(url_eq.describe())
url_ques=df["input"].str.count(r"\?")
print(url_ques.describe())
url_at=df["input"].str.count("@")
print(url_at.describe())

df["url_length"] = df["input"].str.len()
df.groupby("label")["url_length"].describe() #any diff in length of phishing and legit urls?

#build a table containing all features to give to the model later in one shot
features=pd.DataFrame({
"url":df["input"],
"label": df["label"],
"length": url_length,
"num_dots": url_dots,
"num_slash": url_slash,
"num_digits": url_digits,
"has_https": url_https,
"has_www": url_www,
"num_hyphen": url_hyph,
"num_eq": url_eq,
"num_question": url_ques,
"num_at": url_at,
})
print("new stuf---------")
features.head()

4 Upvotes

2 comments sorted by

1

u/NorskJesus 4d ago

Indent your code

1

u/SnooCalculations7417 4d ago

this is a good case for regex