teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

9

誤記修正

2017/09/02 05:26

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -45,7 +45,7 @@
45
45
  print(type(count))
46
46
  print(count.shape)
47
47
  ```
48
- >115.test5.py
48
+ >test5.py
49
49
  (0, 1) 1
50
50
  (0, 7) 1
51
51
  (0, 5) 1

8

質問に情報を追加

2017/09/02 05:26

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -16,52 +16,51 @@
16
16
  以下、count.csvファイルをエディタ等で開いた表示
17
17
  " (0, 0) 29
18
18
  (0, 1) 22
19
- (0, 2) 2
19
+ 省略
20
- (0, 4) 25
21
- (0, 7) 1
22
- (0, 9) 5
23
- (0, 10) 10
24
- (0, 11) 110
25
- (0, 12) 2
26
- (0, 13) 6
27
- (0, 14) 40
28
- (0, 15) 33
29
- (0, 16) 11
30
- (0, 17) 8
31
- (0, 20) 28
32
- (0, 22) 1
33
- (0, 23) 1
34
- (0, 24) 10
35
- (0, 25) 13
36
- (0, 26) 5
37
- (0, 27) 14
38
- (0, 29) 40
39
- (0, 30) 7
40
20
  (0, 31) 6
41
21
  (0, 32) 6
42
22
  : :
43
23
  (0, 28745) 11
44
24
  (0, 28749) 3
45
- (0, 28750) 6
25
+ 省略
46
- (0, 28751) 1
47
- (0, 28753) 5
48
- (0, 28757) 1
49
- (0, 28759) 10
50
- (0, 28760) 1
51
- (0, 28764) 2
52
- (0, 28766) 6
53
- (0, 28767) 93
54
- (0, 28768) 1
55
- (0, 28770) 12
56
- (0, 28771) 25
57
- (0, 28774) 2
58
- (0, 28775) 7
59
- (0, 28779) 58
60
- (0, 28780) 21
61
- (0, 28782) 2
62
- (0, 28784) 13
63
- (0, 28785) 7
64
- (0, 28787) 1
65
- (0, 28790) 2
66
26
  (0, 28791) 1
67
- (0, 28793) 26"
27
+ (0, 28793) 26"
28
+
29
+ 実際のdetaは、test5.pyのサンプルにように単語がブランクで区切られた文字列の配列です。
30
+ countの型とサイズは以下の通りです。
31
+ print(type(count)): <class 'scipy.sparse.csr.csr_matrix'>
32
+ print(count.shape):(1, 28799)
33
+
34
+ <test5.py>
35
+ ```python
36
+ from sklearn.feature_extraction.text import CountVectorizer
37
+ import csv
38
+ data = ['Twinkle twinkle little star' 'How I wonder what you are' 'Up above the world so high' 'Like a diamond in the sky' 'Twinkle twinkle little star' 'How I wonder what you are']
39
+ csvc_vec = CountVectorizer()
40
+ count = csvc_vec.fit_transform(data)
41
+ with open('count.csv', 'wt') as f:
42
+ writer = csv.writer(f)
43
+ writer.writerows(count)
44
+ print(count)
45
+ print(type(count))
46
+ print(count.shape)
47
+ ```
48
+ >115.test5.py
49
+ (0, 1) 1
50
+ (0, 7) 1
51
+ (0, 5) 1
52
+ (0, 3) 1
53
+ (0, 4) 1
54
+ (0, 8) 1
55
+ (0, 14) 1
56
+ (0, 10) 2
57
+ (0, 0) 1
58
+ (0, 2) 1
59
+ (0, 15) 2
60
+ (0, 12) 2
61
+ (0, 13) 2
62
+ (0, 9) 2
63
+ (0, 6) 2
64
+ (0, 11) 3
65
+ <class 'scipy.sparse.csr.csr_matrix'>
66
+ (1, 16)

7

出力の説明を補足

2017/09/02 05:25

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -13,7 +13,7 @@
13
13
  writer = csv.writer(f)
14
14
  writer.writerows(count)
15
15
  ```
16
- 以下、count.csvファイルを開いた内容
16
+ 以下、count.csvファイルをエディタ等で開いた表示
17
17
  " (0, 0) 29
18
18
  (0, 1) 22
19
19
  (0, 2) 2

6

出力結果の説明補足

2017/09/01 06:10

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -13,7 +13,7 @@
13
13
  writer = csv.writer(f)
14
14
  writer.writerows(count)
15
15
  ```
16
-
16
+ 以下、count.csvファイルを開いた内容
17
17
  " (0, 0) 29
18
18
  (0, 1) 22
19
19
  (0, 2) 2

5

サンプルコード修正

2017/09/01 06:07

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -4,10 +4,13 @@
4
4
  全データを出力するにはどうすれば良いでしょうか?
5
5
 
6
6
  ```python
7
+ from sklearn.feature_extraction.text import CountVectorizer
8
+ import csv
9
+
7
- import csvc_vec = CountVectorizer()
10
+ csvc_vec = CountVectorizer()
8
11
  count = c_vec.fit_transform(data)
9
12
  with open('count.csv', 'wt') as f:
10
- writer = csv.writer(f)
13
+ writer = csv.writer(f)
11
14
  writer.writerows(count)
12
15
  ```
13
16
 

4

コードのインデントを修正

2017/09/01 04:37

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  import csvc_vec = CountVectorizer()
8
8
  count = c_vec.fit_transform(data)
9
9
  with open('count.csv', 'wt') as f:
10
- writer = csv.writer(f)
10
+ writer = csv.writer(f)
11
11
  writer.writerows(count)
12
12
  ```
13
13
 

3

コードをMarkdown記法を適用

2017/08/31 13:41

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -3,12 +3,13 @@
3
3
 
4
4
  全データを出力するにはどうすれば良いでしょうか?
5
5
 
6
+ ```python
6
7
  import csvc_vec = CountVectorizer()
7
8
  count = c_vec.fit_transform(data)
8
9
  with open('count.csv', 'wt') as f:
9
- writer = csv.writer(f)
10
+ writer = csv.writer(f)
10
11
  writer.writerows(count)
11
-
12
+ ```
12
13
 
13
14
  " (0, 0) 29
14
15
  (0, 1) 22

2

サンプルコードを修正

2017/08/31 13:40

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
File without changes

1

サンプルコードの入力ミスを修正

2017/08/31 13:34

投稿

okuya
okuya

スコア19

title CHANGED
File without changes
body CHANGED
@@ -4,10 +4,10 @@
4
4
  全データを出力するにはどうすれば良いでしょうか?
5
5
 
6
6
  import csvc_vec = CountVectorizer()
7
- transformed = c_vec.fit_transform(data)
7
+ count = c_vec.fit_transform(data)
8
- with open('data.csv', 'wt') as f:
8
+ with open('count.csv', 'wt') as f:
9
9
  writer = csv.writer(f)
10
- writer.writerows(data)
10
+ writer.writerows(count)
11
11
 
12
12
 
13
13
  " (0, 0) 29