Closed Khawlaa closed 7 years ago
Please post the code you're trying to run in Spyder so we can take a look at it and give you better feedback.
I'm not sure which part I should copy so I attached 2 photos for the whole thing. thank you for your reply
I think you need to change the last line of your code to
img = Image(graph.create_png())
Then by running in the console
img
you'll see the image saved in img
.
thank you sooooo much, I'm so happy finally I did it after struggling.
ok, I had to amend my question.. last question please, it is a very large graph I can't take a screenshot of the whole graph; so my question is there a way to save it without screen shot? and if it is already saved (like autosave) where I can find it?
thank you :)
I really don't know. Maybe there's a graph.save_graph
function to do the job. Sorry for not being of more help.
runfile('C:/Users/GCHF7911/.spyder/temp.py', wdir='C:/Users/GCHF7911/.spyder')
getting this error on running a program. please help
That's not an error, it's just the command used to run files.
then why there's not an output on the terminal?
Because you are not printing anything, i.e. you have to use print(foo)
to see something.
This is my code and I've used print statement also. It's working fine on an online compiler but not on spyder.
from datetime import datetime date_formats = ["%Y-%m-%d %H:%M:%S", "%d-%m-%Y %H:%M:%S", "%m-%d-%Y %H:%M:%S", "%Y/%m/%d %H:%M:%S", "%d/%m/%Y %H:%M:%S", "%m/%d/%Y %H:%M:%S", "%Y.%m.%d %H:%M:%S", "%d.%m.%Y %H:%M:%S", "%m.%d.%Y %H:%M:%S", "%d %b %Y %H:%M:%S", "%b %d %Y %I:%M%p", "%y-%m-%d %H:%M:%S", "%d-%m-%y %H:%M:%S", "%m-%d-%y %H:%M:%S", "%y/%m/%d %H:%M:%S", "%d/%m/%y %H:%M:%S", "%m/%d/%y %H:%M:%S", "%y.%m.%d %H:%M:%S", "%d.%m.%y %H:%M:%S", "%m.%d.%y %H:%M:%S", "%b %d %Y %H:%M:%S", "%Y-%m-%d %H:%M", "%d-%m-%Y %H:%M", "%m-%d-%Y %H:%M", "%d-%m-%Y %H:%M", "%B %d %Y %H:%M:%S", "%d/%m/%Y %H:%M"] match = [] d1 = input() d2 = input() for fmt in date_formats: try: a = datetime.strptime(d1, fmt) b = datetime.strptime(d2, fmt) d = (b-a) day = d.days minutes = day 24 60 print(minutes,'minutes') break except ValueError as e: continue match.append(fmt)
It works for me on Linux.
Hello there are no output after running the code
15]: debugfile('C:/Users/home/Anaconda3/Lib/site-packages/spyder_kernels/customize/fdaa2.py', wdir='C:/Users/home/Anaconda3/Lib/site-packages/spyder_kernels/customize')
c:\users\home\anaconda3\lib\site-packages\spyder_kernels\customize\fdaa2.py(92)
() 90 91 ---> 92 import re 93 import math 94 from collections import deque
pls help
I am getting this error while running my code so please help me to solve this error
can u please help me out with this error http://localhost:8888/notebooks/K%20Shape/Untitled1.ipynb?kernel_name=python3 when I am working with spyder I am getting error
runfile('C:/Users/Administrator/.spyder-py3/untitled01.py', wdir='C:/Users/Administrator/.spyder-py3') Traceback (most recent call last):
File "
File "C:\New folder\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace)
File "C:\New folder\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Administrator/.spyder-py3/untitled01.py", line 199, in
File "C:\Users\Administrator.spyder-py3\doctest.py", line 4, in
ModuleNotFoundError: No module named 'kshape'
Can u please help me out with this error Here is the link of the code http://localhost:8888/notebooks/K%20Shape/Untitled1.ipynb?kernel_name=python3 when I am using spyder I am getting the error
runfile('C:/Users/Administrator/.spyder-py3/untitled01.py', wdir='C:/Users/Administrator/.spyder-py3') Traceback (most recent call last):
File "
File "C:\New folder\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace)
File "C:\New folder\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Administrator/.spyder-py3/untitled01.py", line 199, in
File "C:\Users\Administrator.spyder-py3\doctest.py", line 4, in
ModuleNotFoundError: No module named 'kshape'
Because you are not printing anything, i.e. you have to use
print(foo)
to see something.
Some other people are getting a different output in the console.
Hello AM getting while running the code on spyder runfile('/Users/macbookair/untitled6.py', wdir='/Users/macbookair') mport logging import os import pandas as pd import re import scrapy from scrapy.crawler import CrawlerProcess from scrapy.linkextractors.lxmlhtml import LxmlLinkExtractor from googlesearch import search logging.getLogger('scrapy').propagate = False def get_urls(tag, n, language): urls = [url for url in search(tag, stop=n, lang=language)][:n] return urls get_urls('movie rating', 5 , 'en') class MailSpider(scrapy.Spider): name = 'email' def parse(self, response): links = LxmlLinkExtractor(allow=()).extract_links(response) links = [str(link.url) for link in links] links.append(str(response.url)) for link in links: yield scrapy.Request(url=link, callback=self.parse_link) def parse_link(self, response): for word in self.reject: if word in str(response.url): return html_text = str(response.text) mail_list = re.findall('\w+@\w+.{1}\w+', html_text) dic = {'email': mail_list, 'link': str(response.url)} df = pd.DataFrame(dic) df.to_csv(self.path, mode='a', header=False) df.to_csv(self.path, mode='a', header=False) yield scrapy.Request(url=link, callback=self.parse_link) process = CrawlerProcess({'USER_AGENT': 'Mozilla/5.0'}) process.crawl(MailSpider, start_urls=google_urls, path=path, reject=reject) process.start() def ask_user(question): response = input(question + ' y/n' + '\n') if response == 'y': return True else: return False def create_file(path): response = False if os.path.exists(path): response = ask_user('File already exists, replace?') if response == False: return with open(path, 'wb') as file: file.close() def get_info(tag, n, language, path, reject=[]): create_file(path) df = pd.DataFrame(columns=['email', 'link'], index=[0]) df.to_csv(path, mode='w', header=True) print('Collecting Google urls...') google_urls = get_urls(tag, n, language) print('Searching for emails...') process = CrawlerProcess({'USER_AGENT': 'Mozilla/5.0'}) process.crawl(MailSpider, start_urls=google_urls, path=path, reject=reject) process.start() print('Cleaning emails...') df = pd.read_csv(path, index_col=0) df.columns = ['email', 'link'] df = df.drop_duplicates(subset='email') df = df.reset_index(drop=True) df.to_csv(path, mode='w', header=True) return df def get_info(tag, n, language, path, reject=[]): bad_words = ['facebook', 'instagram', 'youtube', 'twitter', 'wiki'] df = get_info('mastering studio london', 300, 'pt', 'studios.csv', reject=bad_words) df.head() This is my code Please help!
What Wrong with this code ? Output showing like this- runfile('C:/Users/Administrator/.spyder-py3/new.py', wdir='C:/Users/Administrator/.spyder-py3')
def hello(): print("Hello, world!")
def myname(): print("My name is Bill")
def ourschool(): print("Coursera is our school")
runfile('C:/Users/Stuti/Desktop/python/face_eye_detection.py', wdir='C:/Users/Stuti/Desktop/python') pls solve it.
debugfile('F:/Data science classes naresh IT/spyder ML programs/untitled0.py', wdir='F:/Data science classes naresh IT/spyder ML programs')
f:\data science classes naresh it\spyder ml programs\untitled0.py(2)
() 1 ----> 2 import numpy as np #Array 3 4 import matplotlib.pyplot as plt
Hi guys , I'm getting this can anyone help to solve it
@Jangamrumalashivani, you're clicking the debug button several times. That's why you got that result.
runfile('C:/Users/crist/untitled0.py', wdir='C:/Users/crist')
whenever I tried to run a program I get this line, please help
Hey @Khawlaa, that error is already fixed in our latest version (5.3.1).
Since it's still not available in Anaconda, you have two options:
Create a new environment with conda-forge packages. For that, please close Spyder, open the Anaconda Prompt and run the following commands there:
conda create -n spyder-cf -c conda-forge spyder
conda activate spyder-cf
spyder
can someone please help me out .... i have my finals tmo :) this code works in online python compiler but not in Spyder ( im only allowed to use Spyder for my exam) few cases does not work ( like in withd method after printing "insufficient fund" it waits for me to put long input) it would be of great help for me :)
class bank (): def init(self,a): self.balance=100 self.accno=a def depo (self,d): self.balance+=d print("current balnce ",self.balance) def withd(self,w): if w>=self.balance: print("inssuficinet fund ") else : self.balance-=w print("current balnce ",self.balance) def getbal(self): return self.balance def getacc (self): return self.__accno
l1=[]#accno l2=[]#obj l3=[]#max
f=True while(f): c=int(input("1.create 2.deposit 3.withdraw 4.display max ")) if c==1: a=int(input("enter the account number ")) if a in l1: print("account ni already present ") else: l1.append(a) l2.append(bank(a))
if c==2:
try:
a=int(input("enter the account number "))
i=l1.index(a)
d=int(input("enter the amount to be deposited "))
l2[i].depo(d)
except:
print("not found")
if c==3:
try:
a=int(input("enter the account number "))
i=l1.index(a)
w=int(input("enter the amount to be withdrawed "))
l2[i].withd(w)
except:
print("not found")
if c==4:
if len(l1)==0:
print("no account found ")
else :
for i in l2:
l3.append(i.getbal())
j=l3.index(max(l3))
print("acc with max bal is ",l2[j].getacc())
l3=[]
if c==5:
f=False
runfile('C:/Users/Gia/2022-II-LP3-S1-Clases/Semana 06/Tarea/gestion_archivos.py', wdir='C:/Users/Gia/2022-II-LP3-S1-Clases/Semana 06/Tarea') Como solucionar eso me sale
Hola @AnggieBravo, runfile
es el comando que usa Spyder para ejecutar un archivo de Python en la terminal de IPython, o sea que no es un error. Si no te aparece nada más en la terminal, es porque necesitas añadir un comando print
para verlo.
Por ejemplo, para ver el resultado de la siguiente función
def cuadrado(x):
x * x
no sólo basta con llamarla como
cuadrado(5)
sino que debes usar además el comando print
print(cuadrado(5))
import cv2 import matplotlib.pyplot as plt import numpy as np
img=cv2.imread("Resim1.jpg") plt.figure(), plt.imshow(img, cmap = "gray"),plt.title("Orijinal Img")
kernel = np.ones((5,5), dtype = np.uint8) result = cv2.erode(img, kernel, iterations = 1) plt.figure(), plt.imshow(result, cmap = "gray"), plt.axis("off"), plt.title("Erozyon")
görüntü gelmesi lazım çalıştırınca ama gelmiyor
hi I get this when I run this code
runfile('C:/Users/23928352/Desktop/Data/Oulette Data/dVsVs_tailingsmonitoring-v1.0.0/smouellet-dVsVs_tailingsmonitoring-1946c58/dVsVs_model/bootstrap111.py', wdir='C:/Users/23928352/Desktop/Data/Oulette Data/dVsVs_tailingsmonitoring-v1.0.0/smouellet-dVsVs_tailingsmonitoring-1946c58/dVsVs_model')
my code is as followed
import numpy as np import numpy.ma as ma import matplotlib.pyplot as plt import pandas as pd import glob import pickle import warnings from scipy.optimize import curve_fit
def power_law(x, a, b): ''' function to calculate the power-law with constants a and b, power regression https://towardsdatascience.com/basic-curve-fitting-of-scientific-data-with-python-9592244a2509 ''' return a*np.power(x,b)
data =('246.21625, 245.880703, 254.3659374, 225.0877461, 196.1171558, 187.3530337, 194.0158701, 236.8535508, 216.3205735, 219.1345127, 220.1588209, 271.1956852, 252.5096355, 233.5736097, 266.6248149, 232.8743091, 235.0038656, 277.8716508, 273.6499699, 277.0085633, 270.8686827, 263.3479741, 274.9033048, 284.5929077, 300.8185136, 296.2480867, 287.9035012, 287.2630452, 271.0743376, 255.5661895, 255.5661895, 291.1639593, 286.0737274, 286.4689398, 243.7187511, 229.2538056, 233.840115, 272.8896547, 272.8896547, 279.0360369, 314.5366092, 312.7867422, 276.8108809, 225.960588, 217.9049541, 219.5853575, 215.3789965, 211.5859493, 323.9315706, 425.5204681, 425.5204681, 250.5235688, 250.5235688, 214.1308606, 245.7340042, 218.5696358, 206.5665107, 177.4679961, 253.8034486, 205.5990619, 205.5990619, 344.0152026, 344.0152026, 376.7296517, 364.855888, 343.1248006, 390.1699485, 301.4142349, 247.3893319, 209.9995888, 264.9998785, 259.8745213, 240.8566523, 255.8637935, 212.1278014, 173.5940309, 181.2534676, 193.8835929, 202.108593, 202.108593, 225.8572464, 373.7267181, 349.4690514, 317.934763, 300.6035164, 222.5083504, 174.1338717, 176.0705547, 168.0480074, 154.7931281, 242.4449276, 242.4449276, 238.342897, 192.332485, 250.7643385, 223.3885311, 232.3801265, 194.2173653, 277.6332371, 365.2965158, 456.090165, 456.090165, 298.8275148, 317.6707427, 309.8836251, 289.0980759, 229.8881282, 234.5556519, 294.7088213, 294.7088213, 169.7974675, 293.4672123, 301.4334517, 304.7845781, 282.7618765, 367.7037492, 276.2464457, 248.8334961, 239.2417128, 240.3703416, 240.3703416, 262.584183, 335.0056184, 346.7001541, 294.4372556, 223.4427217, 133.7702197, 156.2278439, 223.7919347, 274.381448, 274.381448, 235.4814555, 255.5419823, 217.1501303, 211.0373921, 243.7382609, 208.0963383, 213.9061126, 196.532685, 200.8728168, 207.091911, 267.6096439, 267.6096439, 236.3193636, 261.846135, 202.0992465, 199.3203971, 200.6468243, 398.7929392, 398.7929392, 232.951013, 191.3628842, 200.4850914, 200.4850914, 171.3023566, 180.0908181, 179.1778255, 167.3807663, 189.1671807, 207.7245204, 194.2085167, 208.246051, 208.246051, 330.7298082, 218.0742542, 188.3554354, 190.2516435, 192.3461481, 175.4516827, 181.9345235, 181.9345235, 352.6836804, 405.1741697, 173.3547771, 159.333604, 170.983715, 188.3163853, 174.0108208, 182.8493676, 203.4649293, 195.4139422, 193.2447544, 200.2916516, 188.3593927, 217.3299031, 206.3815359, 239.389073, 239.389073, 109.8719063, 133.9322831, 141.8873023, 139.0889777, 147.1844054, 158.2002649, 174.550106, 198.006545, 185.40981, 174.6694657, 174.6694657, 371.8157898, 245.1494582, 209.5324849, 222.3926607, 217.6424279, 237.437469, 243.7972173, 246.7335377, 261.7483905, 272.1500657, 290.1548193, 237.8545172, 282.1329705, 253.6395842, 280.5967969, 288.0356574, 293.7000681, 294.2935335, 310.3125214, 290.1140555, 290.302592, 292.3461961, 281.9570348, 288.1082233, 282.0352206, 269.8956978, 275.0544891, 288.0189293, 281.1727997, 279.3406941, 279.3406941, 327.1734188, 319.0742873, 315.9119962, 266.8458644, 299.3374991, 266.4431742, 379.0257197, 363.4144692, 441.9695664, 441.9695664, 199.1318645, 199.1318645, 263.6265277, 262.6058405, 331.991056, 176.7435854, 235.096614, 226.5996894, 226.2149551, 198.208141, 219.1823756, 194.1619675, 207.0225975, 181.4101305, 217.1328878, 252.0617249, 238.5602114, 261.2539273, 284.5089939, 260.8955787, 240.3853452, 252.0203495, 249.2583242, 252.4192558, 296.9779632, 289.9485624, 263.8157, 253.2968666, 285.5780332, 285.5780332, 410.5895387, 429.3040235, 345.8897425, 232.9763311, 200.6264331, 299.584674, 321.4020311, 250.8081093, 224.1319024, 287.2615565, 278.3144131, 270.1794385, 294.0645513, 308.2067984, 266.6107718, 290.4333311, 302.2409938, 283.9389982, 313.1884347, 284.7377435, 285.1006959, 313.8072562, 291.8040883, 297.11201, 293.4861514, 310.6104789, 307.8234985, 329.8036122, 321.5647678, 321.5647678, 333.2147325, 305.5004644, 312.7217736, 377.9688268, 320.9038364, 289.7106683, 269.5382596, 260.698032, 265.1000178, 298.2315553, 296.028181, 267.6892841, 256.3272132, 263.9278842, 248.082091, 218.0260848, 208.9734414, 213.9729049, 209.1604321, 209.1604321, 173.5906829, 148.7936493, 158.0587484, 164.169415, 185.8217096, 196.7321825, 229.9467087, 208.3951237, 247.9257186, 211.07948, 209.6935503, 212.712225, 240.9317363, 225.2951094, 252.7072568, 230.9549162, 257.457957, 228.2133134, 236.6163542, 240.1134765, 206.2992653, 199.680213, 174.1092265, 191.6215325, 283.5427561, 283.5427561, 288.5901042, 341.2061448, 310.9588668, 329.5205194, 294.8639416, 249.2967562, 220.6605151, 247.5916124, 255.5854128, 253.9668482, 259.6851969, 279.191733, 252.7609873, 284.9662036, 264.2741484, 206.2007003, 217.0235857, 247.2903054, 281.6088578, 280.7032711, 287.7528254, 276.644414, 261.2921115, 261.2921115, 331.4254607, 262.7862656, 247.3566415, 182.9381598, 199.9964912, 188.4351666, 205.7772277, 199.1055685, 221.7630288, 238.2683937, 221.2413238, 245.1379041, 273.7150184, 243.5690239, 224.9150593, 239.0364127, 249.7212504, 250.0454418, 243.2326406, 245.6694792, 239.275117, 239.4543239, 229.0564568, 223.9312134, 212.6622033, 201.9876617, 187.1457764, 191.3258879, 197.9801834, 205.415518, 205.415518, 402.5081721, 422.0433731, 372.0384116, 307.9691358, 221.6765533, 179.7546664, 188.7270494, 182.4203312, 180.8371899, 164.5803895, 164.5803895, 312.1509879, 357.4524249, 281.4351215, 235.60148, 187.4697207, 224.996642, 230.5621428, 226.5822791, 235.8704632, 217.1018769, 229.0928878, 255.4438396, 232.5573427, 224.3875348, 231.4286414, 211.2260675, 240.7513258, 240.7513258, 215.4645934, 196.5723644, 184.3695215, 180.106284, 181.3382323, 176.0590473, 192.1403145, 176.2245262, 189.6141423, 199.8108362, 185.8091762, 198.0680883, 180.391168, 164.554308, 167.3980963, 158.1845325, 132.6248608, 142.1900336, 142.1900336, 310.2728507, 351.3813557, 206.1171586, 405.6444097, 418.3340559, 374.8931415, 308.0754114, 312.319678, 262.5135126, 257.2688887, 274.2960563, 288.9778449, 329.5868471, 300.7453409, 270.8210543, 291.7113735, 272.2606018, 290.3807975, 292.0878855, 298.587938, 301.3117314, 301.3117314, 294.897008, 284.5617351, 197.4051983, 207.8066863, 161.2929689, 196.0013005, 214.9021, 243.0820578, 237.4407735, 213.2191649, 217.7334219, 200.3249068, 190.7853839, 180.1379585, 180.0348768, 171.5915502, 173.1825299, 184.3866141, 194.9661219, 251.4722985, 251.4722985, 312.9693399, 191.3720702, 157.3580063, 87.52611969, 105.6982485, 130.4819664, 162.0986717, 207.3851551, 207.3851551, 181.2863454, 161.9276149, 212.4493783, 212.4493783, 225.5361488, 140.0691726, 160.738644, 140.4548266, 117.0568039, 119.0822135, 126.5384824, 123.9258051, 123.9258051, 179.1531757, 182.8728116, 164.6567327, 167.5761122, 206.2119421, 206.2119421, 360.0481329, 379.3668766, 376.017036, 313.3442847, 278.5845978, 444.3153406, 602.3403151, 458.3208366, 295.7348843, 306.9619738, 414.7814827, 249.2539431, 236.7596346, 176.4474144, 187.7576923, 290.3795038, 271.7741092, 245.2187771, 199.4450228, 217.8968485, 226.3906795, 226.7335093, 256.2975589, 344.0674151, 344.0674151, 192.9533174, 196.0026534, 156.5724834, 174.5590446, 215.3390767, 154.0618153, 169.8699279, 182.2099677, 177.3976789, 180.3530265, 221.3258517, 251.2906709, 253.2751102, 235.6003731, 219.9704735, 243.4658194, 253.791726, 236.0873556, 248.4984147, 210.674479, 269.7220844, 269.7220844, 258.5407006, 237.897236, 198.7713075, 224.0500963, 200.6265142, 209.990421, 230.7721469, 378.4188088, 366.487218, 221.5958435, 192.9496901, 161.402813, 175.3485934, 174.7604339, 194.4322254, 194.4322254, 429.1239264, 424.7773399, 400.2180265, 261.9587415, 341.9333311, 341.9333311, 237.4692112, 312.5734574, 312.5734574, 165.4031559, 137.950209, 161.8559817, 166.2054328, 161.6733325, 205.6554071, 184.0429107, 189.4340852, 203.7905018, 269.4046805, 269.4046805, 145.8050759, 145.8050759, 355.1097704, 344.097297, 342.2694485, 375.0405578, 370.3276823, 338.2418738, 334.7813183, 269.6236215, 274.762789, 242.6213593, 243.3209458, 220.5765303, 215.9091992, 205.8102661, 210.1874847, 306.8568123, 360.9213679, 292.2418774, 295.7229806, 262.3553292, 245.9797703, 259.5416748, 223.9983735, 179.4790726, 176.3348454, 139.3076465, 140.8399744, 169.5288954, 203.1032181, 210.0909126, 181.3840707, 159.3770215, 156.6138152, 143.427187, 177.5660043, 177.5660043, 221.1485662, 246.6333432, 234.023796, 190.5933392, 188.1054172, 192.7948446, 209.6687428, 184.6660527, 189.1865328, 195.4300376, 203.3291628, 242.9862425, 248.540416, 248.540416, 280.2716401, 183.7214561, 188.5963838, 182.8289109, 220.8643877, 252.7213453, 252.7213453, 250.0213589, 250.0213589, 191.0176936, 197.5182026, 187.5585565, 196.5579562, 184.8026787, 201.8203527, 205.4656049, 232.1156633, 214.8618947, 221.8034396, 238.431593, 212.1766518, 187.1486365, 192.0353179, 216.2345388, 213.9343743, 225.8694265, 243.6350331, 240.7108971, 227.2256251, 231.7299731, 229.7620269, 203.2611891, 256.3744071, 256.3744071, 228.6904242, 205.6295792, 211.9747166, 225.5480614, 225.5480614, 145.1820173, 179.0598974, 81.13566431, 44.35916028, 56.27947339, 127.4106733, 175.9588595, 175.9588595, 312.6100473, 275.6641146, 252.3686081, 185.3865782, 165.6424635, 181.9915077, 174.819639, 185.0169836, 198.4159772, 194.1645725, 215.7423986, 228.7626701, 220.0195696, 247.019007, 230.8782615, 233.6030799, 241.2709411, 244.7686247, 257.023761, 258.5624575, 265.4101121, 262.6023189, 267.4542731, 254.5257923, 273.7304815, 273.0830039, 280.3202852, 284.760288, 283.4220362, 273.5201826, 238.5584324, 248.5804475, 248.5804475, 173, 198, 228, 173, 159, 187, 190, 197, 197, 194, 202, 209, 221, 225, 241, 241, 254, 249, 231, 238, 241, 261, 265, 275, 275, 268, 258, 260, 252, 256, 219, 237, 265, 272, 271, 281, 271, 200, 192, 192, 270, 270, 247, 156, 153, 158, 165, 168, 178, 182, 203, 194, 194, 261, 261')
def get_ecdf(data): ''' Returns x,y for ecdf https://towardsdatascience.com/calculating-confidence-interval-with-bootstrapping-872c657c058d '''
n = len(data)
# We need to sort the data
x = np.sort(data)
# the function will show us cumulative percentages of corresponding data points
y = np.arange(1,n+1)/n
return x,y
def bootstrap(arr, n_boots,unit):
nsampls=int(0.7*(len(arr[:,-1]))) # number of samples reduced to 70% - updated August 8 2022
# POWER LAW REGRESSION ANALYSES
# Fit the sigma_v' vs Vs power-law data
pars, cov = curve_fit(f=power_law, xdata=arr[:,-1], ydata=arr[:,2], p0=[0, 0], bounds=(-np.inf, np.inf))
# Get the standard deviations of the parameters (square roots of the # diagonal of the covariance)
stdevs = np.sqrt(np.diag(cov))
#Calculate the residuals
rest = arr[:,2] - power_law(arr[:,-1], *pars)
alpha=pars[0]
beta=pars[1]
print("Fine tailings regression analyses: ")
#print("Alpha: %0.2f +/- %0.2f m/s; Beta %0.2f +/- %0.2f" %(alpha_tails,stdevst[0],beta_tails,stdevst[1]))
# create power-law dataset based on regression parameters alpha, beta
y_t=np.zeros((len(arr[:,1])))
temp_t=arr[:,-1]
x_t = np.sort(temp_t)
for i in range(len(x_t)):
y_t[i] = alpha*x_t[i]**beta
# resample with replacement each row
boot_beta = [] # BETA
boot_alpha = [] # ALPHA
plt.rcParams["figure.figsize"]=(12,6)
for _ in range(n_boots):
# sample the rows, same size, with replacement
sample_index=np.random.choice(range(0,nsampls),nsampls)
bs_x = arr[:,-1][sample_index]
bs_y=arr[:,2][sample_index]
# fit a linear regression
pars_bs,cov_bs=curve_fit(f=power_law, xdata=bs_x, ydata=bs_y, p0=[0, 0], bounds=(-np.inf, np.inf))
# append coefficients
boot_alpha.append(pars_bs[0])
boot_beta.append(pars_bs[1])
# for individual units (e.g. compact tailings, tailings, clay)
y_bst=np.zeros((len(arr[:,1])))
temp_t=arr[:,-1]
x_bst = np.sort(temp_t)
for i in range(len(x_bst)):
y_bst[i] = boot_alpha[_]*x_bst[i]**boot_beta[_]
# plot a greyed out line
plt.plot(x_bst,y_bst,linewidth=2,color='grey',alpha=0.2) # bootstrap simulations
fsize=1
plt.plot(x_t,y_t,'--r',linewidth=4,label='%s' %(unit)) # power law regression
plt.legend()
plt.plot(arr[:,-1],arr[:,2],'.k') # Vs sCPT data for fine tailings from 2017/18
plt.legend()
plt.xlabel("Effective vertical stress $\sigma_v'$ (kPa)",fontsize=fsize)
plt.ylabel("$V_s$ (m/s)",fontsize=fsize)
plt.tick_params(axis='y', labelsize=fsize)
plt.tick_params(axis='x', labelsize=fsize)
plt.title('Power regression analyses with bootstrap sampling')
plt.grid(True)
plt.show()
plt.savefig('bootstrap_fig_.pdf')
# need larger bootstrap sample to see tails (rare events) - more robust.
# plot histogram of alpha, beta obtained from bootstrap sampling
plt.rcParams["figure.figsize"]=(12,6)
nbins=50 # number of bins used in histogram
# plot alpha histogram
plt.hist(boot_alpha,bins=nbins,color='gray',edgecolor='black')
# Showing the related percentiles
plt.axvline(x=np.percentile(boot_alpha,[2.5]), ymin=0, ymax=1,label='2.5th percentile',c='k')
plt.axvline(x=np.percentile(boot_alpha,[97.5]), ymin=0, ymax=1,label='97.5th percentile',c='k')
plt.xlabel("Alpha (m/s)",fontsize=fsize)
plt.ylabel("PDF",fontsize=fsize)
plt.tick_params(axis='y', labelsize=fsize)
plt.tick_params(axis='x', labelsize=fsize)
plt.title("Probability Density Function")
plt.show()
plt.savefig('bootstrap_alpha_hist_%s.png' % (unit))
# plot beta histogram
plt.hist(boot_beta,bins=nbins,color='gray',edgecolor='black')
# Showing the related percentiles
plt.axvline(x=np.percentile(boot_beta,[2.5]), ymin=0, ymax=1,label='2.5th percentile',c='k')
plt.axvline(x=np.percentile(boot_beta,[97.5]), ymin=0, ymax=1,label='97.5th percentile',c='k')
plt.xlabel("Beta",fontsize=fsize)
plt.ylabel("PDF",fontsize=fsize)
plt.tick_params(axis='y', labelsize=fsize)
plt.tick_params(axis='x', labelsize=fsize)
plt.title("Probability Density Function")
plt.show()
plt.savefig('bootstrap_beta_hist_%s.png' % (unit))
Could you please help me to solve this out?
there are no output after running the file and I keep getting the same message
I'm new in python so I don't know what I have done wrong.. I followed the steps exactly in everything except in the directory because I have a mac and the explaining was in windows.
this first path
is where I saved the file and the next one I don't know what it should be?
I expect to get a DecisionTree graph but I get nothing.
if it is related: I have Graphviz installed and at the beginning of the editing I import some lib and there are some yellow marks saying imported but not used.
Versions and main components
Dependencies
jedi =0.9.0 : 0.9.0 (OK) matplotlib >=1.0 : 2.0.0 (OK) nbconvert >=4.0 : 4.2.0 (OK) numpy >=1.7 : 1.11.3 (OK) pandas >=0.13.1 : 0.19.2 (OK) pep8 >=0.6 : 1.7.0 (OK) psutil >=0.3 : 5.0.1 (OK) pyflakes >=0.6.0 : 1.5.0 (OK) pygments >=2.0 : 2.1.3 (OK) pylint >=0.25 : 1.6.4 (OK) qtconsole >=4.2.0: 4.2.1 (OK) rope >=0.9.4 : 0.9.4-1 (OK) sphinx >=0.6.6 : 1.5.1 (OK) sympy >=0.7.3 : 1.0 (OK)