Что именно я могу сделать, чтобы различить две переменные в моей модели машинного обучения?Python

Программы на Python
Ответить
Anonymous
 Что именно я могу сделать, чтобы различить две переменные в моей модели машинного обучения?

Сообщение Anonymous »

Я использую Kaggle и работаю над набором данных по типированию покемонов: [Таблица типов покемонов][1], и моя модель машинного обучения направлена ​​на то, чтобы принимать пользовательские данные, которые в данном случае являются типом покемонов по их выбору, и отображать выходные данные, которые являются совпадениями типов для этого конкретного ввода. (например, слабость, иммунитет, суперэффективность, сопротивление), но моя вопиющая проблема заключается в том, что в наборе данных есть только три значения, в которых сталкиваются как слабость, так и суперэффективность. Мой мозг полностью выдохся, пытаясь понять предыдущий код.
# Load the dataset
typing_chart = pd.read_csv("/mnt/data/typing_chart.csv")

# Extract unique types
unique_types = typing_chart.columns[1:].tolist()

def type_effectiveness_checker(primary_type, secondary_type="None"):
result = {
"weak": set(), # Types the Pokémon is weak to
"resistant": set(), # Types the Pokémon resists
"immune": set(), # Types the Pokémon is immune to
"effective": set() # Types the Pokémon is super effective against
}

# Function to evaluate effectiveness
def evaluate_effectiveness(attacking_type):
effectiveness_row = typing_chart.loc[typing_chart[typing_chart.columns[0]] == attacking_type].iloc[0]
for defending_type, value in effectiveness_row.items():
if defending_type == typing_chart.columns[0]:
continue # Skip the first column (attacking type label)

if value == 2.0:
result["effective"].add(defending_type) # Super effective against this type
elif value == 0.5:
result["resistant"].add(defending_type) # Resistant to this type
elif value == 0.0:
result["immune"].add(defending_type) # Immune to this type
elif value == 2.0: # Weakness is determined by reverse lookup
reverse_effectiveness = typing_chart.loc[typing_chart[defending_type] == 2.0]
result["weak"].update(reverse_effectiveness[typing_chart.columns[0]].tolist())

# Process primary type
if primary_type in unique_types:
evaluate_effectiveness(primary_type)

# Process secondary type if provided
if secondary_type != "None" and secondary_type in unique_types:
evaluate_effectiveness(secondary_type)

# Format results as sorted lists
result = {key: sorted(values) for key, values in result.items()}
return result

# Gradio function to display effectiveness results
def gradio_type_effectiveness(primary_type, secondary_type):
results = type_effectiveness_checker(primary_type, secondary_type)
return (
f"Weak To: {', '.join(results['weak']) if results['weak'] else 'None'}",
f"Resistant To: {', '.join(results['resistant']) if results['resistant'] else 'None'}",
f"Immune To: {', '.join(results['immune']) if results['immune'] else 'None'}",
f"Super Effective Against: {', '.join(results['effective']) if results['effective'] else 'None'}"
)

# Gradio interface definition
gradio_interface = gr.Interface(
fn=gradio_type_effectiveness,
inputs=[
gr.Dropdown(choices=unique_types, label="Primary Type"),
gr.Dropdown(choices=["None"] + unique_types, label="Secondary Type (Optional)")
],
outputs=[
gr.Textbox(label="Weak To"),
gr.Textbox(label="Resistant To"),
gr.Textbox(label="Immune To"),
gr.Textbox(label="Super Effective Against")
],
title="Pokémon Type Effectiveness Checker",
description="Select a Pokémon's primary and (optional) secondary types to see its type weakness, resistance, immunity, and effectiveness."
)

# Instructions for local use
if __name__ == "__main__":
gradio_interface.launch()

[1]: https://www.kaggle.com/datasets/jadenba ... type-chart


Подробнее здесь: https://stackoverflow.com/questions/793 ... e-learning
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»