필사필요코드 (13) 썸네일형 리스트형 단어의 빈도를 시각화하는 코드 import matplotlib.pyplot as plt from collections import Counter # 예시 리스트 data_list = ["apple", "banana", "apple", "orange", "apple", "banana", "orange", "apple", "orange", "apple"] # 빈도 계산 word_counts = Counter(data_list) # 결과 출력 print("빈도:", word_counts) # 시각화 words = list(word_counts.keys()) counts = list(word_counts.values()) plt.figure(figsize=(10, 6)) plt.bar(words, counts) plt.xlabel('단어').. 불용어 제거 코드 import nltk nltk.download('all') from nltk.corpus import stopwords from nltk.tokenize import word_tokenize stop_words = set(stopwords.words('english')) word_tokens = word_tokenize(exple) result = [] for token in word_tokens: if token not in stop_words: result.append(token) print(len(word_tokens)) print("불용어 제거") #print(result) 생소한 판다스 표현 한글데이터를 판다스로 받기 DataUrl = 'https://raw.githubusercontent.com/Datamanim/pandas/main/Jeju.csv' df = pd.read_csv(DataUrl,encoding='euc-kr') 수치형 변수출력 df.select_dtypes(exclude=object).columns 범주형 변수 출력 Ans = df.select_dtypes(include=object).columns 데이터컬럼의 통계 출력하기 df.describe() IQR구하기 df['평균 속도'].quantile(0.75) -df['평균 속도'].quantile(0.25) 특정컬럼의 값이 3인 경우의 상위 5개 출력 df.loc[df['quantity']==3].head() 위의 행렬을.. 산점도 행렬 출력 sample = trainset.sample(frac=0.05) var = ['ps_car_12', 'ps_car_15', 'target'] sample = sample[var] sns.pairplot(sample, hue='target', palette = 'Set1', diag_kind='kde') plt.show() 상관분석 코드 아래코드를 사용하면 상관 분석이 가능하다 colormap = plt.cm.magma plt.figure(figsize=(16,12)) plt.title('Pearson correlation of continuous features', y=1.05, size=15) sns.heatmap(train_float.corr(),linewidths=0.1,vmax=1.0, square=True, cmap=colormap, linecolor='white', annot=True) #train_int = train_int.drop(["id", "target"], axis=1) # colormap = plt.cm.bone # plt.figure(figsize=(21,16)) # plt.title('Pearson corre.. 컬럼 타입별로 구분 아래 코드를 이용하면 각자의 타입에따라서 출력이 가능하다 Counter(train.dtypes.values) 아래 코드를 이용하면 컬럼이 int형인것과 float64형태로 구분할수있다. train_float = train.select_dtypes(include=['float64']) train_int = train.select_dtypes(include=['int64']) 아래코드를 사용하면 값별 종속성을 알수있다. mf = mutual_info_classif(train_float.values,train.target.values,n_neighbors=3, random_state=17 ) print(mf) 아래 코드는 binal을 알수있는 코드이다. bin_col = [col for col in train.. bar를 통한 count 시각화 x= index.values의 경우는 0과 1값만을 나타내는 리스트를 출력해준다. 이유는 target값에 0과 1밖에 없는 상황이며 현제 가지고 있는 값을 리스트형태로 출력해주는 코드이기때문이다. x= values의 경우는 값이 0과 1밖에없는 행의 갯수를 새어서 리스트형태로 출력해준다. data = [go.Bar( x = train["target"].value_counts().index.values, y = train["target"].value_counts().values, text='Distribution of target variable' )] layout = go.Layout( title='Target variable distribution' ) fig = go.Figure(data=data, .. 캐글 결측치 컬럼별 출력 false값이면 null값이 없음을의미함 그리고 any가 하나면 각컬럼별로 출력함 지금처럼 두개인경우는 전체를 살펴보는 코드임 # any() applied twice to check run the isnull check across all columns. train.isnull().any().any() 시각화 import missingno as msno # Nullity or missing values by columns msno.matrix(df=train_copy.iloc[:,2:39], figsize=(20, 14), color=(0.42, 0.1, 0.05)) seaborn 시본 형제수에 따른 생존률 import seaborn as sns import matplotlib.pyplot as plt # catplot을 사용하여 막대 그래프 그리기 g = sns.catplot(x="SibSp", y="Survived", data=train, kind="bar", height=6, palette="muted") g.despine(left=True) g.set_ylabels("survival probability") plt.show() 캐글의 bert 최종 전처리 #전처리할 컬럼 options = 'ABCDE' # 컬럼의 갯수 indices = list(range(5)) option_to_index = {option: index for option, index in zip(options, indices)} index_to_option = {index: option for option, index in zip(options, indices)} def preprocess(example): # The AutoModelForMultipleChoice class expects a set of question/answer pairs # so we'll copy our question 5 times before tokenizing first_sentence = [example.. 이전 1 2 다음 목록 더보기