Data Analytics Codes
Klausur
Klausur
Fichier Détails
Cartes-fiches | 65 |
---|---|
Langue | English |
Catégorie | Finances |
Niveau | Université |
Crée / Actualisé | 08.02.2025 / 08.02.2025 |
Lien de web |
https://card2brain.ch/box/20250208_data_analytics_codes
|
Intégrer |
<iframe src="https://card2brain.ch/box/20250208_data_analytics_codes/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Créer ou copier des fichiers d'apprentissage
Avec un upgrade tu peux créer ou copier des fichiers d'apprentissage sans limite et utiliser de nombreuses fonctions supplémentaires.
Connecte-toi pour voir toutes les cartes.
What is the Python code of a line chart using matplotlib?
sns.lineplot(x="Date", y="Ridership", data=trains_df)
What is the Python code for a bar chart representing the median using seaborn?
from numpy import median sns.barplot(x="CHAS", y="MEDV", data=housing_df, estimator=median)
What is the Python code for a bar chart representing the arithmetic mean using seaborn?
from numpy import mean sns.barplot(x="CHAS", y="MEDV", data=housing_df, estimator=mean)
What is the Python code for a bar chart using seaborn?
sns.countplot(x="CHAS", data=housing_df)
What is the Python code for a histogram using seaborn?
sns.histplot(data=housing_df, x="MEDV")
Visualization of the distribution of a continuous variable.
What is the Python code for grouped boxplots using seaborn?
sns.boxplot(y=housing_df["MEDV"], x=housing_df["CHAS"], whis=[0,100])
What is the Python code for boxplots using seaborn?
sns.boxplot(y=housing_df["MEDV"], whis=[0,100])
What is the Python code for the correlation matrix?
housing_df.corr().round(2)
What is the Python code for the scatter plot matrix in Python using seaborn?
sns.pairplot(housing_df[['CRIM', 'INDUS', 'LSTAT', 'MEDV']])
What is the code of rescale in Python?
res_bed = (housing_df["BEDROOMS"] - housing_df["BEDROOMS"].min()) / (housing_df["BEDROOMS"].max() - housing_df["BEDROOMS"].min()) res_bed.describe()
What is the code of standardisation in Python?
norm_df = (housing_df - housing_df.mean()) / housing_df.std() norm_df.describe()
What is the code to show the first 5 lines of the dataset?
housing_df.head()
What is the code to show the dimension of the dataset?
housing_df.shape
What is the code for descriptive analysis of the dataset housing?
housing_df.describe()
What is the Python code to generate a lift chart?
import kds as kds
kds.metrics.plot_lift(valid_y, predict_valid)
What is the Python code to make a confusion matrix?
predict_valid = logit_reg.predict(valid_X) cm2 = confusion_matrix(valid_y, predict_valid)
ConfusionMatrixDisplay(cm2).plot()
X = banking_df[["Income", "Family", "CCAvg", "Education", "Age"]] X = pd.get_dummies(X, prefix_sep="_", drop_first=True) Y = banking_df["has_mortgage"]# Data partitioningtrain_X, valid_X, train_y, valid_y = train_test_split(X, Y, test_size=0.4, random_state=10)# Logistic Regression logit_reg = LogisticRegression(solver="liblinear")logit_reg.fit(train_X, train_y)
What is the Python code to add explanatory variables and estimate it again?
X_full = banking_df[["Income", "Family", "CCAvg", "Education", "Age"]] X_full = pd.get_dummies(X_full, prefix_sep="_", drop_first=True)
X_full = X_full.astype(float) # Make sure that all columns have numerical data types
Y_full = banking_df["has_mortgage"] X_full = sm.add_constant
(X_full)logit_full_mod = sm.Logit(Y_full, X_full)
logit_full_mod_res = logit_full_mod.fit()print(logit_full_mod_res.summary())
What is the Python code to estimate a logit model: log(odds(has.mortgage = 1| income) = ß0 + ß1 * income?
X_simple = banking_df["Income"]
Y_simple = banking_df["has_mortgage"]
X_simple = sm.add_constant
(X_simple)logit_simple_mod = sm.Logit
(Y_simple, X_simple)logit_simple_mod_res = logit_simple_mod.fit()print(logit_simple_mod_res.summary())
What is the Python code to generate a new variable that takes the value 0 when Mortgage has the value 0 and takes the value 1 in all other cases?
banking_df["has_mortgage"] = [0 if x == 0 else 1 for x in banking_df["Mortgage"]]
banking_df.head()
What is the Python code to convert a variable into a categorical variable?
banking_df["Education"].value_counts().sort_index()
banking_df["Education"] = banking_df["Education"].map({1: "Undergrad", 2: "Graduate", 3: "Advanced/Professional"})
banking_df.head()
What is the Python code to replace the spaces in all variable names with underscores _?
banking_df.columns = [s.strip().replace(" ", "_") for s in banking_df.columns] banking_df.head()
What is the Python code to show the regression statistics of validation data?
print('Performance Measures (Validation data)') regressionSummary(valid_y, toyota_ml.predict(valid_X))
What is the Python code to show the regression statistics of training data?
print('Performance Measures (Training data)') regressionSummary(train_y, toyota_ml.predict(train_X))
What is the Python code for regression statistics?
# Fuel_Type transform in Dummies
X = toyota_df[['Fuel_Type', 'HP']]
y = toyota_df[['Price']]# Transform Fuel_Type in dummies
X = pd.get_dummies(X, drop_first=True)# Split the datatrain_X, valid_X, train_y,
valid_y = train_test_split(X, y, test_size=0.4)# Model
fittingtoyota_ml = LinearRegression()toyota_ml.fit(train_X, train_y)
What is the Python code for an OLS Regression to appreciate the influence of a variable based on another variable?
modg_X = toyota_df[['Fuel_Type']
]modg_X = pd.get_dummies(modg_X, drop_first=True)
modg_X = sm.add_constant(modg_X)
modg_X = modg_X.astype(float) # Make sure that all columns have numerical values# Model estimation and results
modg = sm.OLS(toyota_df['Price'], modg_X)res = modg.fit()print(res.summary())
What is the Python code to visualize the relationship between the selling price and the type of fuel in a stripplot?
with pd.option_context('mode.use_inf_as_na', True): sns.set(rc={'figure.figsize':(10,8), "figure.dpi":300,})
sns.set_theme(style="whitegrid")sns.stripplot(x="Fuel_Type", y="Price", data=toyota_df)
What is the Python code to visualize the relationship between the selling price and the type of fuel in a swarmplot?
with pd.option_context('mode.use_inf_as_na', True): sns.set(rc={'figure.figsize':(13,5), "figure.dpi":300,})
sns.set_theme(style="whitegrid")sns.swarmplot(x="Fuel_Type", y="Price", data=toyota_df, size=4)
What is the Python code to visualize the relationship between the selling price and the type of fuel in a boxplot?
sns.boxplot(x="Fuel_Type", y="Price", data=toyota_df, whis=100)
-
- 1 / 65
-