Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Felix Newsgroups: fr.comp.lang.python Subject: =?UTF-8?Q?Re=3a_Difficult=c3=a9_pour_d=c3=a9velopper_une_fonction?= Date: Wed, 11 Mar 2020 22:35:52 +0100 Organization: A noiseless patient Spider Lines: 98 Message-ID: References: Reply-To: slad@keemail.me Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 11 Mar 2020 21:35:57 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="36c9c05349732e1c2509469d3723bf29"; logging-data="25153"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CZSotwPWj2o44ecvD3b618P9ocw+y2FA=" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 Cancel-Lock: sha1:uR3GqwK0b0A3Xz8UoNbDqmPQdos= In-Reply-To: Content-Language: fr Xref: csiph.com fr.comp.lang.python:3298 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)) + '%' ) >