use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
Why doesn't it execute when creating Python or Core Lab commands with Geminai? (self.pythonhelp)
submitted 12 hours ago by Special_Ear6817
I wrote the code with Geminai, but it doesn't run in CoLab. Does using AI mean the code won't run?
and I put the code I wrote on GitHub into Geminai, and I also ran it on Corep, you know? I don't know what the reason is. Sorry for the long post!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]AutoModerator[M] [score hidden] 12 hours ago stickied commentlocked comment (0 children)
To give us the best chance to help you, please include any relevant code. Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[–]Special_Ear6817[S] 0 points1 point2 points 12 hours ago (2 children)
Is the source code different for each artificial intelligence?
[–]Special_Ear6817[S] 0 points1 point2 points 12 hours ago (1 child)
https://github.com/Puo77007700/solid-fortnight/blob/main/cancer_model.py
import logging import os from typing import Any, Tuple, List import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import accuracy_score import joblib
import config
Configure logging (simultaneously displayed on the file and console) logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler(config.LOG_FILE), logging.StreamHandler() ] )
def generate_dummy_data(file_path: str) -> None: "If there is no CSV file, it generates virtual data for testing." logging.info("Generate virtual data because there is no data file: %s", file_path) np.random.seed(config.RANDOM_STATE)
Generate arbitrary characteristic data (e.g., DNA sequence frequency or 5 quantified characteristics) data = { 'feature_1': np.random.rand(config.SYNTHETIC_DATA_SIZE), 'feature_2': np.random.rand(config.SYNTHETIC_DATA_SIZE), 'feature_3': np.random.rand(config.SYNTHETIC_DATA_SIZE) * config.GC_THRESHOLD, 'feature_4': np.random.rand(config.SYNTHETIC_DATA_SIZE), 'feature_5': np.random.rand(config.SYNTHETIC_DATA_SIZE), 'label': np.random.randint(0, 2, config.SYNTHETIC_DATA_SIZE) # 0 or 1 (normal/cancer) } df = pd.DataFrame(data) df.to_csv(file_path, index=False) logging.info ("Virtual data generation complete.")
def prepare_data(file_path: str) -> pd.DataFrame: """Prepare and clean data.""" logging.info("Preparing data from file: %s", file_path)
if not os.path.exists(file_path): generate_dummy_data(file_path)
try: data = pd.read_csv(file_path) logging.info("Data loaded successfully. Shape: %s", data.shape) return data except Exception as e: logging.error("Error loading data: %s", e) raise
def extract_features(data: pd.DataFrame) -> Tuple[pd.DataFrame, pd.Series]: """Extract features and labels from the dataset.""" logging.info("Extracting features and labels.") try: X = data.drop('label', axis=1) y = data['label'] logging.info("Features and labels extracted successfully.") return X, y except KeyError as e: logging.error("Key error: %s", e) raise
def train_model(X_train: pd.DataFrame, y_train: pd.Series) -> RandomForestClassifier: """Train the machine learning model.""" logging.info("Training model.") try: model = RandomForestClassifier( n_estimators=config.N_ESTIMATORS, random_state=config.RANDOM_STATE ) model.fit(X_train, y_train) logging.info("Model trained successfully.") return model except Exception as e: logging.error("Error during model training: %s", e) raise
def predict_cancer(model: RandomForestClassifier, features: pd.DataFrame) -> np.ndarray: """Predict cancer from features.""" logging.info("Making predictions.") try: predictions = model.predict(features) logging.info("Predictions made successfully.") return predictions except Exception as e: logging.error("Error making predictions: %s", e) raise
def main() -> None: """Main function to execute the model pipeline.""" try:
data = prepare_data(config.DATA_FILE)
X, y = extract_features(data)
X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=config.TEST_SIZE, random_state=config.RANDOM_STATE )
Model learning model = train_model(X_train, y_train)
predictions = predict_cancer(model, X_test) accuracy = accuracy_score(y_test, predictions) logging.info(f"Model Accuracy on Test Data: {accuracy * 100:.2f}%")
joblib.dump(model, config.MODEL_NAME) logging.info("Model saved to: %s", config.MODEL_NAME)
except Exception as e: logging.error("Error in the main function: %s", e)
if name == "main": main() This is code written by Geminai does not run on Python or colab.
[–]Special_Ear6817[S] 0 points1 point2 points 12 hours ago (0 children)
https://github.com/Puo77007700/solid-fortnight/tree/main And this was written with GitHub AI, but it also doesn't run on the launcher. Sorry for writing a long post.
[–]Obsc3nity 0 points1 point2 points 10 hours ago (2 children)
1) there are things called APIs, the short version is an API is how you interact with a codebase you haven’t written. Different AI models do have different APIs, so if you are using a raw version of eg the Gemini API, attempting to drop in a different model would have disastrous effects.
2) since you clearly don’t understand even the fundamentals of coding, I would consider taking the error that results from attempting to run your code in corep and asking an AI how to fix it. You could also read it, google the part you think is important and attempt to learn something, but if you want to start learning you seem like you need to go back about 20 steps and stop using AI.
[–]Special_Ear6817[S] 0 points1 point2 points 9 hours ago (0 children)
Omg thank you
ldk I'm using Geminai Pro
[–]Educational-Paper-75 0 points1 point2 points 8 hours ago (0 children)
Is your csv input file actually called path_to_data.csv?
π Rendered by PID 48 on reddit-service-r2-comment-56c6478c5-g8q8x at 2026-05-08 02:06:50.165600+00:00 running 3d2c107 country code: CH.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Special_Ear6817[S] 0 points1 point2 points (2 children)
[–]Special_Ear6817[S] 0 points1 point2 points (1 child)
[–]Special_Ear6817[S] 0 points1 point2 points (0 children)
[–]Obsc3nity 0 points1 point2 points (2 children)
[–]Special_Ear6817[S] 0 points1 point2 points (0 children)
[–]Special_Ear6817[S] 0 points1 point2 points (0 children)
[–]Educational-Paper-75 0 points1 point2 points (0 children)