data-science

How to Remove IndentationError: expected an indented block: except ValueError: in Google Colab

How to Remove IndentationError: expected an indented block: except ValueError: in Google Colab Question: Given a dataset I was asked to perform 5 machine learning models on the dataset. Here is my code: standard_scaler = StandardScaler() try: X_train=standard_scaler.fit_transform(X_train) X_test=standard_scaler.fit_transform(X_test) except ValueError: I keep getting except ValueError: ^ IndentationError: expected an indented block Can someone please …

Total answers: 1

refactor age imputation

refactor age imputation Question: How can I refactor the following code to make sure it easier to read and better using a function. Can reproduce code and data frames used using GitHub https://github.com/hamidpat/titanic posted csv used on my github. import numpy as np import pandas as pd train_df = pd.read_csv("train_df.csv") test_df = pd.read_csv("test_df.csv.csv") combine = …

Total answers: 2

How do i select cells in a column that contain date type values in pandas

How do i select cells in a column that contain date type values in pandas Question: I want to look up the row that contains Transitioning EIN in the Unnamed 17 column and the date of 2021-01-29 in Unnamed 13 column. pic I tried this: df.loc[(df[‘Unnamed: 17′]==’Transitioning EIN’) & (df[‘Unnamed: 13’]=="2021-01-29 00:00:00")] which returns an …

Total answers: 1

SOLVED – VS Code startup <conda active base> error message

VS Code startup <conda active base> error message Question: I just getting started learning with Anaconda on Visual Studio Code. Previously, I only used the Python as an interpreter. After downloaded the Anaconda and upon opening the VS Code I always encounter the following error message. PS C:UsersuserDocumentsPythonLearn> conda activate base conda : The term …

Total answers: 2

Trying to predict probability score using test data

Trying to predict probability score using test data Question: I’m currently trying to test features and impacts to probability score on regression model we’ve built. I’m trying to test impacts of age on proba score to see if we need to retrain our model. I’m using parameters from our model as Param_Collection and using test …

Total answers: 1

How can I make sure my constraint can operate mathematically with the LpVariable?

How can I make sure my constraint can operate mathematically with the LpVariable? Question: I am trying to use the pulb libraries classes to solve a LP-Problem. I am having problems implementing the constraint into my code. After importing the relevant classes and reading from my CSV file I wrote: prob = pulp.LpProblem("Optimal Number of …

Total answers: 1

how to imitate Pandas' index-based querying in Polars?

how to imitate Pandas' index-based querying in Polars? Question: Any idea what I can do to imitate the below pandas code using polars? Polars doesn’t have indexes like pandas so I couldn’t figure out what I can do . df = pd.DataFrame(data = ([21,123], [132,412], [23, 43]), columns = [‘c1’, ‘c2’]).set_index("c1") print(df.loc[[23, 132]]) and it …

Total answers: 1

How do I solve an import issue with numpy in scikit.decomposition.PCA?

How do I solve an import issue with numpy in scikit.decomposition.PCA? Question: I was trying to use the scikit.decomposition.PCA package and I couldn’t even import it. import numpy as np from sklearn.decomposition import PCA I’ve upgraded both of np and scikit, but the error seems to be w/in scikit, what should I do? *Note: Using …

Total answers: 1

Masking the Zip Codes

Masking the Zip Codes Question: I’m taking a course and I need to solve the following assignment: "In this part, you should write a for loop, updating the df_users dataframe. Go through each user, and update their zip code, to Safe Harbor specifications: If the user is from a zip code for the which the …

Total answers: 1

mat1 and mat2 shapes cannot be multiplied (1×7 and 1×1)

mat1 and mat2 shapes cannot be multiplied (1×7 and 1×1) Question: I am using a linear regression model in PyTorch to predict number of cars sold from car price using fake data: car_price_tensor tensor([3., 4., 5., 6., 7., 8., 9.]) number_of_car_sell_tensor tensor([[7.5000], [7.0000], [6.5000], [6.0000], [5.5000], [5.0000], [4.5000]]) Here’s the network: import torch.nn as nn …

Total answers: 1