This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pandas استدعاء مكتبة | |
import pandas as pd | |
from IPython.display import display | |
# سحب البيانات واستعراضها على هيئة إطار بيانات | |
diamonds = pd.read_csv('Datasets/diamonds.csv') | |
# عرض إطار البيانات | |
display(diamonds.head()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pie chart تمثيل النسب المئوية لفئات النشاط البدني من خلال الرسم البياني | |
plt.figure(figsize=(16,8)) | |
plt.pie(df_activity_count['Counts'], labels = df_activity_count.index, autopct = '%0.2f') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# تدريب نموذج الانحدار اللوجستي للتنبؤ بأمراض القلب | |
from sklearn.linear_model import LogisticRegression | |
lr_clf = LogisticRegression(solver='liblinear') | |
lr_clf.fit(X_train, y_train) | |
# طباعة تقرير أداء النموذج | |
print_score(lr_clf, X_test, y_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# تقسيم مجموعة البيانات إلى بيانات تدريب و اختبار | |
from sklearn.model_selection import train_test_split | |
X = dataset.drop('target', axis=1) | |
y = dataset.target | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# استدعاء دوال لقياس أداء النموذج | |
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report | |
# دالة طباعة تقرير أداء نموذج التصنيف | |
def print_score(clf, X_test, y_test): | |
pred = clf.predict(X_test) | |
clf_report = pd.DataFrame(classification_report(y_test, pred, output_dict=True)) | |
print("_______________________________________________") | |
print(f"Accuracy Score: {accuracy_score(y_test, pred) * 100:.2f}%") | |
print("_______________________________________________") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df.drop('target', axis=1).corrwith(df.target).plot(kind='bar', grid=True, figsize=(12, 8), | |
title="Correlation with target") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# تصوير على هيئة خريطة حرارية لتمثيل العلاقة الترابطية بين الميزات | |
corr_matrix = df.corr() | |
fig, ax = plt.subplots(figsize=(15, 15)) | |
ax = sns.heatmap(corr_matrix, | |
annot=True, | |
linewidths=0.5, | |
fmt=".2f", | |
cmap="YlGnBu"); | |
bottom, top = ax.get_ylim() | |
ax.set_ylim(bottom + 0.5, top - 0.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# تصوير البيانات الخاصة بالميزات الرقمية المتصلة بالنسبة لحالة الشخص (وجود مرض قلبي من عدمه) | |
plt.figure(figsize=(15, 15)) | |
for i, column in enumerate(continous_val, 1): | |
plt.subplot(3, 2, i) | |
df[df["target"] == 0][column].hist(bins=35, color='blue', label='Have Heart Disease = NO', alpha=0.6) | |
df[df["target"] == 1][column].hist(bins=35, color='red', label='Have Heart Disease = YES', alpha=0.6) | |
plt.legend() | |
plt.xlabel(column) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# EDA استيراد المكتبات اللازمة لتحليل البيانات الاستكشافي | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
import numpy as np | |
# تعيين تفضيلات الخلفية في الرسوم البيانية | |
%matplotlib inline | |
sns.set_style("whitegrid") | |
plt.style.use("fivethirtyeight") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# استدعاء المكتبات | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# سحب البيانات | |
data = pd.read_csv("data/uber-raw-data-sep14.csv") | |
# التعديل على صيغة التاريخ من شهر/يوم//سنة إلى يوم-شهر-سنة | |
data["Date/Time"] = data["Date/Time"].map(pd.to_datetime) |
NewerOlder