Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Difficulté pour développer une fonction

2 réponses
Avatar
heevy
Bonjour,

Je dois développer une fonction permettant de trier un type d'objet pour savoir s'ils sont vrai ou faux. Ma fonction doit pouvoir lire un fichier et déterminer si les objets sont vrai ou faux.

Voici mon code, pourriez vous m'aider?

illet=pd.read_csv("notes.csv")
b2 =pd.read_csv("example.csv")


feature_names = ["diagonal", "height_left","height_right", "margin_low","margin_up", "length" ]

X1 = billet[feature_names]
y1 = billet["is_genuine"]

model = sm.OLS(y1, X1)
results = model.fit()

X2 = b2[feature_names]

b2['résultats'] = results.predict(X2).values
b2['statut'] = np.where(b2['résultats']>=0.5, 'vrai', 'faux')

b2.drop(columns=["diagonal","height_left","height_right","margin_low","margin_up","length"],axis=1,inplace=True)


#nourrir le modèle
logreg = LogisticRegression()
logreg.fit(X1,y1)

import random
from random import*
y=choices(y1, k=5)

#prévision
y_pred = logreg.predict(X2)



#graphique répartition vrai/faux billet
b2["statut"].value_counts(normalize=True).plot(kind='pie', autopct =lambda x: str(round(x, 2)) + '%' )


#fonction

def lire(nom):

return pd.read_csv(nom)
lire ("example.csv")

feature_names = ["diagonal", "height_left","height_right", "margin_low","margin_up", "length" ]

X1 = billet[feature_names]
y1 = billet["is_genuine"]

model = sm.OLS(y1, X1)
results = model.fit()

X2 = nom[feature_names]

nom['résultats'] = results.predict(X2).values
nom['statut'] = np.where(nom['résultats']>=0.5, 'vrai', 'faux')

nom.drop(columns=["diagonal","height_left","height_right","margin_low","margin_up","length"],axis=1,inplace=True)


#nourrir le modèle
logreg = LogisticRegression()
logreg.fit(X1,y1)

import random
from random import*
y=choices(y1, k=5)

#prévision
y_pred = logreg.predict(X2)



#graphique répartition vrai/faux billet
nom["statut"].value_counts(normalize=True).plot(kind='pie', autopct =lambda x: str(round(x, 2)) + '%' )

2 réponses

Avatar
Nicolas
Bonjour,
Pour avoir de l'aide il faut :
1- Décrire précisément la problématique.
2- Fournir un code utilisable le plus simple possible.
3- Expliquer ce qui pose problème.
1-> La description est trop vague. Qu'est-ce qu'un objet vrai ou faux ?
Qu'est-ce qui est lu dans le fichier ?...
2-> Dès la première ligne on peut voir que le code n'est pas fonctionnel
: pd n'existe pas.
3-> "Voici mon code, pourriez vous m'aider?" : Aider à quoi ? Qu'est-ce
qui pose problème ?
Cordialement,
Nicolas
Le 04/03/2020 à 08:19, heevy a écrit :
Bonjour,
Je dois développer une fonction permettant de trier un type d'objet pour savoir
s'ils sont vrai ou faux. Ma fonction doit pouvoir lire un fichier et déterminer
si les objets sont vrai ou faux.
Voici mon code, pourriez vous m'aider?
illet=pd.read_csv("notes.csv")
b2 =pd.read_csv("example.csv")
feature_names = ["diagonal", "height_left","height_right",
"margin_low","margin_up", "length" ]
X1 = billet[feature_names]
y1 = billet["is_genuine"]
model = sm.OLS(y1, X1)
results = model.fit()
X2 = b2[feature_names]
b2['résultats'] = results.predict(X2).values
b2['statut'] = np.where(b2['résultats']>=0.5, 'vrai', 'faux')
b2.drop(columns=["diagonal","height_left","height_right","margin_low","margin_up","length"],axis=1,inplace=True)
#nourrir le modèle
logreg = LogisticRegression()
logreg.fit(X1,y1)
import random
from random import*
y=choices(y1, k=5)
#prévision
y_pred = logreg.predict(X2)
#graphique répartition vrai/faux billet
b2["statut"].value_counts(normalize=True).plot(kind='pie', autopct =lambda x:
str(round(x, 2)) + '%' )
#fonction
def lire(nom):
return pd.read_csv(nom)
lire ("example.csv")
feature_names = ["diagonal", "height_left","height_right",
"margin_low","margin_up", "length" ]
X1 = billet[feature_names]
y1 = billet["is_genuine"]
model = sm.OLS(y1, X1)
results = model.fit()
X2 = nom[feature_names]
nom['résultats'] = results.predict(X2).values
nom['statut'] = np.where(nom['résultats']>=0.5, 'vrai', 'faux')
nom.drop(columns=["diagonal","height_left","height_right","margin_low","margin_up","length"],axis=1,inplace=True)
#nourrir le modèle
logreg = LogisticRegression()
logreg.fit(X1,y1)
import random
from random import*
y=choices(y1, k=5)
#prévision
y_pred = logreg.predict(X2)
#graphique répartition vrai/faux billet
nom["statut"].value_counts(normalize=True).plot(kind='pie', autopct =lambda x:
str(round(x, 2)) + '%' )
Avatar
Felix
Bonjour,
Il serait intéressant d'avoir une visibilité sur le contenu des
dataframes. On se doute du début manquant de ton code, mais ce serait
plus confortable si tu pouvais le corriger :)
Merci, en espérant pouvoir t'aider davantage.
Le 04/03/2020 à 08:19, heevy a écrit :
Bonjour,
Je dois développer une fonction permettant de trier un type d'objet pour savoir
s'ils sont vrai ou faux. Ma fonction doit pouvoir lire un fichier et déterminer
si les objets sont vrai ou faux.
Voici mon code, pourriez vous m'aider?
illet=pd.read_csv("notes.csv")
b2 =pd.read_csv("example.csv")
feature_names = ["diagonal", "height_left","height_right",
"margin_low","margin_up", "length" ]
X1 = billet[feature_names]
y1 = billet["is_genuine"]
model = sm.OLS(y1, X1)
results = model.fit()
X2 = b2[feature_names]
b2['résultats'] = results.predict(X2).values
b2['statut'] = np.where(b2['résultats']>=0.5, 'vrai', 'faux')
b2.drop(columns=["diagonal","height_left","height_right","margin_low","margin_up","length"],axis=1,inplace=True)
#nourrir le modèle
logreg = LogisticRegression()
logreg.fit(X1,y1)
import random
from random import*
y=choices(y1, k=5)
#prévision
y_pred = logreg.predict(X2)
#graphique répartition vrai/faux billet
b2["statut"].value_counts(normalize=True).plot(kind='pie', autopct =lambda x:
str(round(x, 2)) + '%' )
#fonction
def lire(nom):
return pd.read_csv(nom)
lire ("example.csv")
feature_names = ["diagonal", "height_left","height_right",
"margin_low","margin_up", "length" ]
X1 = billet[feature_names]
y1 = billet["is_genuine"]
model = sm.OLS(y1, X1)
results = model.fit()
X2 = nom[feature_names]
nom['résultats'] = results.predict(X2).values
nom['statut'] = np.where(nom['résultats']>=0.5, 'vrai', 'faux')
nom.drop(columns=["diagonal","height_left","height_right","margin_low","margin_up","length"],axis=1,inplace=True)
#nourrir le modèle
logreg = LogisticRegression()
logreg.fit(X1,y1)
import random
from random import*
y=choices(y1, k=5)
#prévision
y_pred = logreg.predict(X2)
#graphique répartition vrai/faux billet
nom["statut"].value_counts(normalize=True).plot(kind='pie', autopct =lambda x:
str(round(x, 2)) + '%' )